mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Danish Khateeb <danishkhateeb03@gmail.com>
Cc: Willy Tarreau <w@1wt.eu>, Shuah Khan <shuah@kernel.org>,
	 linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] tools/nolibc: fix fopen() errno when open() fails
Date: Thu, 29 Oct 2026 18:38:53 +0100	[thread overview]
Message-ID: <e7898648-5934-46ad-a4dd-94d2bfe258ae@t-8ch.de> (raw)
In-Reply-To: <20261028200743.154151-2-danishkhateeb03@gmail.com>

On 2026-10-28 15:07:41-0500, Danish Khateeb wrote:
> When open() fails, fopen() passes its -1 on to fdopen(), which sets
> errno to EBADF and so overwrites the error from open(). A missing file
> is reported as EBADF instead of ENOENT, and a file without permission as
> EBADF instead of EACCES.
> 
> Return NULL as soon as open() fails, leaving its errno in place.
> 
> Fixes: a009a0c6faa9 ("tools/nolibc: add fopen()")
> Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>

Thanks!

Reviewed-by: Thomas Weißschuh <linux@weissschuh.net>

> ---
>  tools/include/nolibc/stdio.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
> index ebdd413d13ec..00a95a267d90 100644
> --- a/tools/include/nolibc/stdio.h
> +++ b/tools/include/nolibc/stdio.h
> @@ -79,6 +79,9 @@ FILE *fopen(const char *pathname, const char *mode)
>  		flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
>  
>  	fd = open(pathname, flags, 0666);
> +	if (fd < 0)
> +		return NULL;
> +
>  	return fdopen(fd, mode);
>  }

  reply	other threads:[~2026-10-29 17:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 20:07 [PATCH 0/3] tools/nolibc: fix fopen() errno and "rb+" modes Danish Khateeb
2026-10-28 20:07 ` [PATCH 1/3] tools/nolibc: fix fopen() errno when open() fails Danish Khateeb
2026-10-29 17:38   ` Thomas Weißschuh [this message]
2026-10-28 20:07 ` [PATCH 2/3] tools/nolibc: fix fopen() with the "rb+", "wb+" and "ab+" modes Danish Khateeb
2026-10-29 17:41   ` Thomas Weißschuh
2026-10-28 20:07 ` [PATCH 3/3] selftests/nolibc: test fopen() errors and update modes Danish Khateeb
2026-10-29 17:47   ` 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=e7898648-5934-46ad-a4dd-94d2bfe258ae@t-8ch.de \
    --to=linux@weissschuh.net \
    --cc=danishkhateeb03@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@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®