mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Palmer <daniel@thingy.jp>
To: w@1wt.eu, linux@weissschuh.net
Cc: linux-kernel@vger.kernel.org, Daniel Palmer <daniel@thingy.jp>
Subject: [PATCH 1/3] tools/nolibc: unistd: Add getcwd()
Date: Sat,  2 May 2026 16:25:25 +0900	[thread overview]
Message-ID: <20260502072527.1805108-2-daniel@thingy.jp> (raw)
In-Reply-To: <20260502072527.1805108-1-daniel@thingy.jp>

Add getcwd() for getting the current working directory.

Signed-off-by: Daniel Palmer <daniel@thingy.jp>
---
 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


  reply	other threads:[~2026-05-02  7:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-02  7:25 [PATCH 0/3] nolibc: Add getcwd() and readlink() Daniel Palmer
2026-05-02  7:25 ` Daniel Palmer [this message]
2026-05-02 13:41   ` [PATCH 1/3] tools/nolibc: unistd: Add getcwd() Thomas Weißschuh
2026-05-05  9:07     ` Daniel Palmer
2026-05-02  7:25 ` [PATCH 2/3] tools/nolibc: unistd: Add readlink() Daniel Palmer
2026-05-02 13:42   ` Thomas Weißschuh
2026-05-02  7:25 ` [PATCH 3/3] selftests/nolibc: Add test for getcwd() and readlink() Daniel Palmer
2026-05-02 13:43   ` Thomas Weißschuh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260502072527.1805108-2-daniel@thingy.jp \
    --to=daniel@thingy.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    --cc=w@1wt.eu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®