Opened 4 months ago
Last modified 4 months ago
#19039 new bug
fpurge does not update the file position when discarding pending input
Reported by: | bhaible | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | Unscheduled |
Component: | System/libroot.so | Version: | R1/beta5 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description
The description of the fpurge function is as follows:
From the Linux man pages https://man7.org/linux/man-pages/man3/fpurge.3.html : "The function fpurge() clears the buffers of the given stream. For output streams this discards any unwritten output. For input streams this discards any input read from the underlying object but not yet obtained via getc(3); this includes any text pushed back via ungetc(3)."
From Gnulib https://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob;f=lib/stdio.in.h;h=36fd6a72ceb7e1a64563e0a45ea1d6650fad1fc6;hb=HEAD#l631 : "Discard all pending buffered I/O data on STREAM. STREAM must not be wide-character oriented. When discarding pending output, the file position is set back to where it was before the write calls. When discarding pending input, the file position is advanced to match the end of the previously read input. Return 0 if successful. Upon error, return -1 and set errno."
The part regarding input streams does not work in Haiku hrev57823 (from 2024-07-15).
How to reproduce: Compile and run the attached program.
gcc -Wall foo.c printf 'foogarsh' > foo.tmp ./a.out
Expected output (such as on glibc):
ftell (fp) = 8 OK
Actual output:
ftell (fp) = 7 a.out: foo.c:36:main: ftell (fp) == 8 Kill Thread
Attachments (1)
Change History (2)
by , 4 months ago
comment:1 by , 4 months ago
I've replaced the fpurge implementation with upstream glibc's in hrev58060. However that doesn't seem to fix this problem.
test case foo.c