From: David Laight <david.laight.linux@gmail.com>
To: Daniel Palmer <daniel@thingy.jp>
Cc: w@1wt.eu, linux@weissschuh.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] tools/nolibc: Add fread() to stdio.h
Date: Mon, 5 Jan 2026 11:01:42 +0000 [thread overview]
Message-ID: <20260105110142.127eaba3@pumpkin> (raw)
In-Reply-To: <CAFr9PXkO-iGFVpe6w=WobnMUe-6Eiw+fq+B_pq1G3Su5cmnD1Q@mail.gmail.com>
On Mon, 5 Jan 2026 18:43:03 +0900
Daniel Palmer <daniel@thingy.jp> wrote:
> Hi David,
>
> On Mon, 5 Jan 2026 at 18:27, David Laight <david.laight.linux@gmail.com> wrote:
> > But you've deleted the partial bytes from the input.
> > I'm sure that isn't right.
> > Normally a FILE is buffered and the bytes are saved for the next read.
> > Remember you can be reading from a pipe that is being written using
> > 'block buffering' - so it is valid for only a partial 'item' be read.
> > (I'm sure non-blocking IO is also valid...)
>
> I see now. If a partial read happens, the next call to fread() will
> read from after the end of the partial read that happened and it'll be
> broken.
> Since in nolibc the FILE pointer that gets used isn't really a pointer
> but the file descriptor I'm not sure where we'd stash the partial part
> so we need to avoid doing the partial read entirely.
Except you can't really avoid the partial read.
Doing multiple read() system calls doesn't help.
The situation where it can happen probably doesn't happen for nolibc.
Is there support for ferror() and/or feof() ?
(a global 'u8 fstate[64]' indexed by fd number would probably suffice.)
If so you could set the 'error' bit and then error any further fread()s.
David
>
> Thanks,
>
> Daniel
next prev parent reply other threads:[~2026-01-05 11:01 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-04 8:38 [PATCH 0/2] nolibc: Add fread() and fseek() Daniel Palmer
2026-01-04 8:38 ` [PATCH 1/2] tools/nolibc: Add fread() to stdio.h Daniel Palmer
2026-01-04 9:13 ` Thomas Weißschuh
2026-01-04 18:34 ` David Laight
2026-01-05 0:54 ` Daniel Palmer
2026-01-05 9:27 ` David Laight
2026-01-05 9:43 ` Daniel Palmer
2026-01-05 11:01 ` David Laight [this message]
2026-01-06 11:02 ` Thomas Weißschuh
2026-01-06 11:07 ` Willy Tarreau
2026-01-04 8:38 ` [PATCH 2/2] tools/nolibc: Add fseek() " Daniel Palmer
2026-01-04 9:11 ` [PATCH 0/2] nolibc: Add fread() and fseek() Thomas Weißschuh
2026-01-04 11:12 ` Daniel Palmer
2026-01-04 12:42 ` Willy Tarreau
2026-01-04 14:36 ` 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=20260105110142.127eaba3@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=daniel@thingy.jp \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--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