[PATCH v2 0/3] nolibc: Add getcwd() and readlink()

From: Daniel Palmer

Date: Tue Jun 30 2026 - 09:24:42 EST


I needed getcwd() for something. So I added that, then realised
I also needed readlink() to test the result of getcwd().

This adds getcwd() and readlink() then adds a test that uses
both.

Note: getcwd() has some behaviour where if the current directory
is unreachable then the kernel returns "(unreachable)" and this
needs some special handling. I checked what musl was doing for
this. It seems pretty difficult to test and maybe needs some
calls nolibc doesn't have yet. Basically: It looks right but
there is no test.

v2:
- Addressed Thomas' comments for readlink() and making the test depend on proc.
- Filled out getcwd() so it matches what musl is doing.
- Expanded the test a little to try to cover passing bad arguments.

Daniel Palmer (3):
tools/nolibc: unistd: Add getcwd()
tools/nolibc: unistd: Add readlink()
selftests/nolibc: Add test for getcwd() and readlink()

tools/include/nolibc/unistd.h | 56 ++++++++++++++++++++
tools/testing/selftests/nolibc/nolibc-test.c | 48 +++++++++++++++++
2 files changed, 104 insertions(+)

--
2.53.0