musl/src/stdio
Rich Felker 3af2edee15 fix ftello result for append streams with unflushed output
when there is unflushed output, ftello (and ftell) compute the logical
stream position as the underlying file descriptor's offset plus an
adjustment for the amount of buffered data. however, this can give the
wrong result for append-mode streams where the unflushed writes should
adjust the logical position to be at the end of the file, as if a seek
to end-of-file takes place before the write.

the solution turns out to be a simple trick: when ftello (indirectly)
calls lseek to determine the current file offset, use SEEK_END instead
of SEEK_CUR if the stream is append-mode and there's unwritten
buffered data.

the ISO C rules regarding switching between reading and writing for a
stream opened in an update mode, along with the POSIX rules regarding
switching "active handles", conveniently leave undefined the
hypothetical usage cases where this fix might lead to observably
incorrect offsets.

the bug being fixed was discovered via the test case for glibc issue
2014-02-07 00:57:50 -05:00
..
__fclose_ca.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
__fdopen.c fix ftello result for append streams with unflushed output 2014-02-07 00:57:50 -05:00
__fmodeflags.c greatly improve freopen behavior 2012-10-24 21:16:06 -04:00
__fopen_rb_ca.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
__lockfile.c document self-synchronized destruction issue for stdio locking 2012-12-10 18:31:39 -05:00
__overflow.c major stdio overhaul, using readv/writev, plus other changes 2011-03-28 01:14:44 -04:00
__stdio_close.c global cleanup to use the new syscall interface 2011-03-20 00:16:43 -04:00
__stdio_exit.c fix more unused variable warnings 2012-11-01 23:46:39 -04:00
__stdio_read.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
__stdio_seek.c don't disable seeking after first seek failure 2011-04-02 13:55:54 -04:00
__stdio_write.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
__stdout_write.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
__string_read.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
__toread.c fix missing function declarations for __stdio_exit 2012-07-02 22:48:56 -04:00
__towrite.c fix missing function declarations for __stdio_exit 2012-07-02 22:48:56 -04:00
__uflow.c fix getc - the classic error of trying to store EOF+0-255 in a char type.. 2011-03-28 17:31:01 -04:00
asprintf.c cleanup asprintf stuff 2011-02-20 17:19:37 -05:00
clearerr.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
dprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
ext.c change stdio_ext __freading/__fwriting semantics slightly 2012-06-17 21:24:58 -04:00
ext2.c fix invalid implicit pointer conversion in gnulib-compat functions 2012-09-06 23:27:55 -04:00
fclose.c fix more unused variable warnings 2012-11-01 23:46:39 -04:00
feof.c correct locking in stdio functions that tried to be lock-free 2012-10-24 23:16:41 -04:00
ferror.c correct locking in stdio functions that tried to be lock-free 2012-10-24 23:16:41 -04:00
fflush.c minor cleanup in fflush 2012-06-19 01:12:36 -04:00
fgetc.c separate getc/putc from fgetc/fputc 2012-10-27 19:52:40 -04:00
fgetln.c include cleanups: remove unused headers and add feature test macros 2013-12-12 05:09:18 +00:00
fgetpos.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
fgets.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fgetwc.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fgetws.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fileno.c correct locking in stdio functions that tried to be lock-free 2012-10-24 23:16:41 -04:00
flockfile.c add proper fuxed-based locking for stdio 2011-07-30 08:02:14 -04:00
fmemopen.c always add memory streams to stdio open file list 2012-11-09 14:26:25 -05:00
fopen.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
fputc.c separate getc/putc from fgetc/fputc 2012-10-27 19:52:40 -04:00
fputs.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fputwc.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fputws.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fread.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
freopen.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fscanf.c fix argument omission in ABI-compat weak_alias for fscanf 2013-04-06 17:15:58 -04:00
fseek.c apparently fseek should not set the error flag on failed seek 2011-04-02 13:54:55 -04:00
fsetpos.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
ftell.c fix ftello result for append streams with unflushed output 2014-02-07 00:57:50 -05:00
ftrylockfile.c clean up sloppy nested inclusion from pthread_impl.h 2012-11-08 17:04:20 -05:00
funlockfile.c add proper fuxed-based locking for stdio 2011-07-30 08:02:14 -04:00
fwide.c include cleanups: remove unused headers and add feature test macros 2013-12-12 05:09:18 +00:00
fwprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
fwrite.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
fwscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
getc.c separate getc/putc from fgetc/fputc 2012-10-27 19:52:40 -04:00
getc_unlocked.c add some ugly aliases for LSB ABI compatibility 2012-06-02 21:20:21 -04:00
getchar.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
getchar_unlocked.c major stdio overhaul, using readv/writev, plus other changes 2011-03-28 01:14:44 -04:00
getdelim.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
getline.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
gets.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
getw.c make sure getw/putw agree with prototypes by defining _GNU_SOURCE 2012-07-04 12:18:46 -04:00
getwc.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
getwchar.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
open_memstream.c always add memory streams to stdio open file list 2012-11-09 14:26:25 -05:00
open_wmemstream.c always add memory streams to stdio open file list 2012-11-09 14:26:25 -05:00
pclose.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
perror.c minor perror behavior fix 2012-06-20 09:27:28 -04:00
popen.c fix special-case breakage in popen due to reversed argument order 2013-09-01 17:02:35 -04:00
printf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
putc.c separate getc/putc from fgetc/fputc 2012-10-27 19:52:40 -04:00
putc_unlocked.c add some ugly aliases for LSB ABI compatibility 2012-06-02 21:20:21 -04:00
putchar.c initial check-in, version 0.5.0 2011-02-12 00:22:29 -05:00
putchar_unlocked.c major stdio overhaul, using readv/writev, plus other changes 2011-03-28 01:14:44 -04:00
puts.c minor optimization in puts: use inline putc_unlocked macro for newline 2011-05-01 20:12:51 -04:00
putw.c putw is supposed to return 0 (not the value written) on success 2012-07-04 12:21:22 -04:00
putwc.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
putwchar.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
remove.c fix messed-up errno if remove fails for a non-EISDIR reason 2011-03-29 08:25:59 -04:00
rename.c global cleanup to use the new syscall interface 2011-03-20 00:16:43 -04:00
rewind.c rewind must clear the error indicator in addition to seeking 2011-02-22 17:11:35 -05:00
scanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
setbuf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
setbuffer.c add more legacy functions: setlinebuf and setbuffer 2011-04-05 12:25:31 -04:00
setlinebuf.c add more legacy functions: setlinebuf and setbuffer 2011-04-05 12:25:31 -04:00
setvbuf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
snprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
sprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
sscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
stderr.c add proper fuxed-based locking for stdio 2011-07-30 08:02:14 -04:00
stdin.c add proper fuxed-based locking for stdio 2011-07-30 08:02:14 -04:00
stdout.c add proper fuxed-based locking for stdio 2011-07-30 08:02:14 -04:00
swprintf.c include cleanups: remove unused headers and add feature test macros 2013-12-12 05:09:18 +00:00
swscanf.c include cleanups: remove unused headers and add feature test macros 2013-12-12 05:09:18 +00:00
tempnam.c avoid 64bit warnings when using pointers as entropy for temp names 2011-06-13 20:52:01 -04:00
tmpfile.c debloat: use __syscall instead of syscall where possible 2011-04-17 16:32:15 -04:00
tmpnam.c avoid 64bit warnings when using pointers as entropy for temp names 2011-06-13 20:52:01 -04:00
ungetc.c major stdio overhaul, using readv/writev, plus other changes 2011-03-28 01:14:44 -04:00
ungetwc.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
vasprintf.c cleanup asprintf stuff 2011-02-20 17:19:37 -05:00
vdprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
vfprintf.c minor vfprintf and vfwprintf changes to please static code analyzers 2013-10-07 13:22:24 +00:00
vfscanf.c add __isoc99_vfscanf weak alias to vfscanf 2014-01-08 22:52:26 +01:00
vfwprintf.c minor vfprintf and vfwprintf changes to please static code analyzers 2013-10-07 13:22:24 +00:00
vfwscanf.c include cleanups: remove unused headers and add feature test macros 2013-12-12 05:09:18 +00:00
vprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
vscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
vsnprintf.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
vsprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
vsscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
vswprintf.c clean up stdio_impl.h 2012-11-08 16:39:41 -05:00
vswscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
vwprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
vwscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00
wprintf.c use restrict everywhere it's required by c99 and/or posix 2008 2012-09-06 22:44:55 -04:00
wscanf.c Add ABI compatability aliases. 2013-04-05 23:20:28 -07:00