mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore: Add File method to determine current working directory
This commit is contained in:
parent
a3400798f8
commit
3ae64c7c3d
Notes:
sideshowbarker
2024-07-18 09:05:31 +09:00
Author: https://github.com/timmot Commit: https://github.com/SerenityOS/serenity/commit/3ae64c7c3d8 Pull-request: https://github.com/SerenityOS/serenity/pull/8586 Reviewed-by: https://github.com/alimpfard ✅
2 changed files with 15 additions and 0 deletions
|
@ -193,6 +193,20 @@ bool File::ensure_parent_directories(const String& path)
|
|||
return rc == 0;
|
||||
}
|
||||
|
||||
String File::current_working_directory()
|
||||
{
|
||||
char* cwd = getcwd(nullptr, 0);
|
||||
if (!cwd) {
|
||||
perror("getcwd");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto cwd_as_string = String(cwd);
|
||||
free(cwd);
|
||||
|
||||
return cwd_as_string;
|
||||
}
|
||||
|
||||
#ifdef __serenity__
|
||||
|
||||
String File::read_link(String const& link_path)
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
|
||||
static bool exists(const String& filename);
|
||||
static bool ensure_parent_directories(const String& path);
|
||||
static String current_working_directory();
|
||||
|
||||
enum class RecursionMode {
|
||||
Allowed,
|
||||
|
|
Loading…
Reference in a new issue