Opened 3 weeks ago

Last modified 2 weeks 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)

foo.c (950 bytes ) - added by bhaible 3 weeks ago.
test case foo.c

Download all attachments as: .zip

Change History (2)

by bhaible, 3 weeks ago

Attachment: foo.c added

test case foo.c

comment:1 by waddlesplash, 2 weeks ago

I've replaced the fpurge implementation with upstream glibc's in hrev58060. However that doesn't seem to fix this problem.

Note: See TracTickets for help on using tickets.