mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] tools/nolibc: fix fopen() errno and "rb+" modes
@ 2026-10-28 20:07 Danish Khateeb
  2026-10-28 20:07 ` [PATCH 1/3] tools/nolibc: fix fopen() errno when open() fails Danish Khateeb
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Danish Khateeb @ 2026-10-28 20:07 UTC (permalink / raw)
  To: Willy Tarreau, Thomas Weißschuh
  Cc: Shuah Khan, linux-kselftest, linux-kernel, Danish Khateeb

fopen() has two bugs:

- When open() fails, fopen() overwrites its errno with EBADF, so a
  missing file is reported as EBADF instead of ENOENT.

- "rb+", "wb+" and "ab+" are not recognised as update modes, so the
  stream is opened read-only or write-only.

Patches 1 and 2 fix them. Patch 3 adds nolibc-test cases for both.

Tested on top of nolibc/for-next 700ce4da6f6f, on x86_64 (GCC and
clang) and i386, and on arm, arm64 and sparc64 under qemu-user:

- nolibc-test, all tests: no failures with the series. The only
  difference from before is the three new tests, which pass. They also
  pass against glibc (make libc-test).

- Without patches 1 and 2, all three new tests fail on every build.

- On x86_64, a separate program opening a file with each of the twelve
  C mode strings now gets the same access mode from nolibc as from
  glibc, and the same errno for ENOENT and EACCES failures.

An LLM was used to help with this series.

Danish Khateeb (3):
  tools/nolibc: fix fopen() errno when open() fails
  tools/nolibc: fix fopen() with the "rb+", "wb+" and "ab+" modes
  selftests/nolibc: test fopen() errors and update modes

 tools/include/nolibc/stdio.h                 |  5 +++-
 tools/testing/selftests/nolibc/nolibc-test.c | 24 ++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)


base-commit: 700ce4da6f6f172435349b687d2d916e791c6330
-- 
2.56.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-28 20:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-28 20:07 ` [PATCH 2/3] tools/nolibc: fix fopen() with the "rb+", "wb+" and "ab+" modes Danish Khateeb
2026-10-28 20:07 ` [PATCH 3/3] selftests/nolibc: test fopen() errors and update modes Danish Khateeb

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®