summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-11-15 21:13:36 +0100
committerAnton Kling <anton@kling.gg>2023-11-15 22:11:26 +0100
commit835101f96e7c9fca00940e967c471c33e4e4dae9 (patch)
tree9c48b871d4b547fac8c3a2eda6c21242e593fdfd /userland
parentc9358cdeac4522922df46fb6e3ab6a517203ec99 (diff)
VFS/LibC: Add getcwd()
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/include/syscall.h1
-rw-r--r--userland/libc/include/unistd.h3
-rw-r--r--userland/libc/unistd/getcwd.c6
-rw-r--r--userland/minibox/utilities/ls.c6
4 files changed, 13 insertions, 3 deletions
diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h
index bd1d9fc..32d7b33 100644
--- a/userland/libc/include/syscall.h
+++ b/userland/libc/include/syscall.h
@@ -37,6 +37,7 @@
#define SYS_KILL 29
#define SYS_SIGACTION 30
#define SYS_CHDIR 31
+#define SYS_GETCWD 32
int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx,
uint32_t esi, uint32_t edi);
diff --git a/userland/libc/include/unistd.h b/userland/libc/include/unistd.h
index 5654752..89c48d0 100644
--- a/userland/libc/include/unistd.h
+++ b/userland/libc/include/unistd.h
@@ -20,6 +20,7 @@ int unlink(const char *path);
int execvp(const char *file, char *const argv[]);
void _exit(int status);
void msleep(uint32_t ms); // not standard
-uint32_t uptime(void); // not standard
+uint32_t uptime(void); // not standard
int chdir(const char *path);
+char *getcwd(char *buf, size_t size);
#endif
diff --git a/userland/libc/unistd/getcwd.c b/userland/libc/unistd/getcwd.c
new file mode 100644
index 0000000..6050c95
--- /dev/null
+++ b/userland/libc/unistd/getcwd.c
@@ -0,0 +1,6 @@
+#include <syscall.h>
+#include <unistd.h>
+
+char *getcwd(char *buf, size_t size) {
+ return syscall(SYS_GETCWD, buf, size, NULL, NULL, NULL);
+}
diff --git a/userland/minibox/utilities/ls.c b/userland/minibox/utilities/ls.c
index dc93d36..bedc3a3 100644
--- a/userland/minibox/utilities/ls.c
+++ b/userland/minibox/utilities/ls.c
@@ -22,14 +22,16 @@ int ls_main(int argc, char **argv) {
}*/
struct dirent **namelist;
int n;
- COND_PERROR_EXP(-1 == (n = scandir("/", &namelist, 0, 0)), "scandir",
+ char path[256];
+ (void)getcwd(path, 256);
+ COND_PERROR_EXP(-1 == (n = scandir(path, &namelist, 0, 0)), "scandir",
return 1);
int prev = 0;
for (int i = 0; i < n; i++) {
if (!list_hidden)
if ('.' == *namelist[i]->d_name)
- continue;
+ continue;
if (prev)
putchar(newline ? '\n' : ' ');