瀏覽代碼

Add getwd().

Andreas Kling 6 年之前
父節點
當前提交
e5e0bffd76
共有 4 個文件被更改,包括 11 次插入1 次删除
  1. 3 0
      LibC/limits.h
  2. 1 1
      LibC/sys/param.h
  3. 5 0
      LibC/unistd.cpp
  4. 2 0
      LibC/unistd.h

+ 3 - 0
LibC/limits.h

@@ -0,0 +1,3 @@
+#pragma once
+
+#define PATH_MAX 4096

+ 1 - 1
LibC/sys/param.h

@@ -1,4 +1,4 @@
 #pragma once
 
 #include <endian.h>
-
+#include <limits.h>

+ 5 - 0
LibC/unistd.cpp

@@ -156,6 +156,11 @@ char* getcwd(char* buffer, size_t size)
     __RETURN_WITH_ERRNO(rc, buffer, nullptr);
 }
 
+char* getwd(char* buf)
+{
+    return getcwd(buf, PATH_MAX);
+}
+
 int sleep(unsigned seconds)
 {
     return Syscall::invoke(Syscall::SC_sleep, (dword)seconds);

+ 2 - 0
LibC/unistd.h

@@ -2,6 +2,7 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
+#include <limits.h>
 
 __BEGIN_DECLS
 
@@ -29,6 +30,7 @@ int close(int fd);
 pid_t waitpid(pid_t, int* wstatus, int options);
 int chdir(const char* path);
 char* getcwd(char* buffer, size_t size);
+char* getwd(char* buffer);
 int lstat(const char* path, struct stat* statbuf);
 int stat(const char* path, struct stat* statbuf);
 int sleep(unsigned seconds);