[PATCH 1/3] tools/nolibc: unistd: Add getcwd()

From: Daniel Palmer

Date: Sat May 02 2026 - 03:26:03 EST


Add getcwd() for getting the current working directory.

Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>
---
tools/include/nolibc/unistd.h | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h
index 5882a6862066..c7f89c56bc9b 100644
--- a/tools/include/nolibc/unistd.h
+++ b/tools/include/nolibc/unistd.h
@@ -48,6 +48,28 @@ int access(const char *path, int amode)
return faccessat(AT_FDCWD, path, amode, 0);
}

+/*
+ * char *getcwd(char *buf, size_t size);
+ */
+
+static __attribute__((unused))
+int _sys_getcwd(char *buf, size_t size)
+{
+ return __nolibc_syscall2(__NR_getcwd, buf, size);
+}
+
+static __attribute__((unused))
+char *getcwd(char *buf, size_t size)
+{
+ /* If successful we get the number of bytes written into
+ * the buffer, so check the result is positive.
+ */
+ if (__sysret(_sys_getcwd(buf, size)) > 0)
+ return buf;
+
+ /* On error return NULL, __sysret() above will have set errno */
+ return NULL;
+}

static __attribute__((unused))
int msleep(unsigned int msecs)
--
2.53.0