Re: [PATCH 2/3] tools/nolibc: unistd: Add readlink()
From: Thomas Weißschuh
Date: Sat May 02 2026 - 09:43:05 EST
May 2, 2026 09:25:44 Daniel Palmer <daniel@xxxxxxxxx>:
> Add readlink(). This is needed to test getcwd();
>
> Signed-off-by: Daniel Palmer <daniel@xxxxxxxxx>
> ---
> tools/include/nolibc/unistd.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/tools/include/nolibc/unistd.h b/tools/include/nolibc/unistd.h
> index c7f89c56bc9b..309a4e0e65d2 100644
> --- a/tools/include/nolibc/unistd.h
> +++ b/tools/include/nolibc/unistd.h
> @@ -84,6 +84,26 @@ int msleep(unsigned int msecs)
> return 0;
> }
>
> +/*
> + * ssize_t readlink(const char *path, char *buf, size_t bufsiz);
> + */
> +
> +static __attribute__((unused))
> +ssize_t _sys_readlink(const char *path, char *buf, size_t bufsiz)
> +{
> +#ifdef __NR_readlink
> + return __nolibc_syscall3(__NR_readlink, path, buf, bufsiz);
> +#else
> + return __nolibc_syscall4(__NR_readlinkat, AT_FDCWD, path, buf, bufsiz);
> +#endif
Every architecture should have readli kat, no?
Then I think we can drop the fallback to regular readlink.
> +}
> +
> +static __attribute__((unused))
> +ssize_t readlink(const char *path, char *buf, size_t bufsiz)
> +{
> + return __sysret(_sys_readlink(path, buf, bufsiz));
> +}
> +
> static __attribute__((unused))
> unsigned int sleep(unsigned int seconds)
> {
> --
> 2.53.0