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 2/3] tools/nolibc: fix fopen() with the "rb+", "wb+" and "ab+" modes
Date: Thu, 29 Oct 2026 18:41:36 +0100 [thread overview]
Message-ID: <3de13984-b78a-465c-8a48-4e916187b41e@t-8ch.de> (raw)
In-Reply-To: <20261028200743.154151-3-danishkhateeb03@gmail.com>
On 2026-10-28 15:07:42-0500, Danish Khateeb wrote:
> The C standard allows the '+' of an update mode to come before or after
> the 'b', so "rb+" means the same as "r+b". fopen() only looks for the
> '+' right after the first character, so it opens a file read-only in
> "rb+" mode, and write-only in "wb+" and "ab+" modes. Writing to such a
> stream, or reading from it, then fails with EBADF.
>
> Look for the '+' anywhere in the mode string.
>
> Fixes: a009a0c6faa9 ("tools/nolibc: add fopen()")
The original implementation explicitly does not support 'b'.
I guess we can add support for it, but then the Fixes is misplaced
and the message needs to be reworded.
> Signed-off-by: Danish Khateeb <danishkhateeb03@gmail.com>
> ---
> tools/include/nolibc/stdio.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h
> index 00a95a267d90..205b06f18b4b 100644
> --- a/tools/include/nolibc/stdio.h
> +++ b/tools/include/nolibc/stdio.h
> @@ -75,7 +75,7 @@ FILE *fopen(const char *pathname, const char *mode)
> SET_ERRNO(EINVAL); return NULL;
> }
>
> - if (mode[1] == '+')
> + if (strchr(mode, '+'))
> flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
>
> fd = open(pathname, flags, 0666);
> --
> 2.56.0
>
next prev parent reply other threads:[~2026-10-29 17:41 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
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 [this message]
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=3de13984-b78a-465c-8a48-4e916187b41e@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®