diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 8c582a8a293..197995e0345 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -301,6 +301,17 @@ ErrorOr gethostname() return String(&hostname[0]); } +ErrorOr getcwd() +{ + auto* cwd = ::getcwd(nullptr, 0); + if (!cwd) + return Error::from_syscall("getcwd"sv, -errno); + + String string_cwd(cwd); + free(cwd); + return string_cwd; +} + ErrorOr ioctl(int fd, unsigned request, ...) { va_list ap; diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index dc7bc79455d..8adef7d2f83 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -53,6 +53,7 @@ ErrorOr dup(int source_fd); ErrorOr dup2(int source_fd, int destination_fd); ErrorOr ptsname(int fd); ErrorOr gethostname(); +ErrorOr getcwd(); ErrorOr ioctl(int fd, unsigned request, ...); ErrorOr tcgetattr(int fd); ErrorOr tcsetattr(int fd, int optional_actions, struct termios const&);