mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Daniel Palmer <daniel@thingy.jp>
Cc: w@1wt.eu, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] tools/nolibc: Add dirfd()
Date: Fri, 28 Aug 2026 14:15:23 +0200	[thread overview]
Message-ID: <e201e5d8-b3cf-44a4-a1ce-a578ec9d9aec@t-8ch.de> (raw)
In-Reply-To: <20260828112204.104111-1-daniel@thingy.jp>

On 2026-08-28 20:22:04+0900, Daniel Palmer wrote:
> This is useful for things like fstatat() on children of directory
> opened with opendir().
> 
> At the same time use it to replace the two places that are converting
> the DIR point back into an fd.
> 
> Signed-off-by: Daniel Palmer <daniel@thingy.jp>
> ---
>  tools/include/nolibc/dirent.h | 38 +++++++++++++++++++++++++++--------
>  1 file changed, 30 insertions(+), 8 deletions(-)
> 
> diff --git a/tools/include/nolibc/dirent.h b/tools/include/nolibc/dirent.h
> index 4e02ef25e72d..ba229b215a0b 100644
> --- a/tools/include/nolibc/dirent.h
> +++ b/tools/include/nolibc/dirent.h
> @@ -27,6 +27,18 @@ typedef struct {
>  	char dummy[1];
>  } DIR;
>  
> +/* Internal dirfd() that does not set errno */
> +static __attribute__((unused))
> +int nolibc_dirfd(DIR *dirp)

This pollutes the applications symbol namespace.
It should begin with underscores.
But IMO we could also just keep it inlined in the two users.

> +{
> +	intptr_t i = (intptr_t)dirp;
> +
> +	if (i >= 0)
> +		return -1;
> +
> +	return ~i;
> +}

Could you also add a test for an fdopendir() -> dirfd() roundtrip?


Thomas

      reply	other threads:[~2026-08-28 12:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 11:22 Daniel Palmer
2026-08-28 12:15 ` Thomas Weißschuh [this message]

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=e201e5d8-b3cf-44a4-a1ce-a578ec9d9aec@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=daniel@thingy.jp \
    --cc=linux-kernel@vger.kernel.org \
    --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®