LibCore: Add File method to determine current working directory

This commit is contained in:
Timothy 2021-07-10 01:29:07 +10:00 committed by Ali Mohammad Pur
parent a3400798f8
commit 3ae64c7c3d
Notes: sideshowbarker 2024-07-18 09:05:31 +09:00
2 changed files with 15 additions and 0 deletions

View file

@ -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)

View file

@ -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,