Red Hat Bugzilla – Bug 81359
after fopen(, "a+") ftell() gives 0 not EOF
Last modified: 2007-03-26 23:59:50 EDT
Description of problem:
Bug report courtesy of PHP CVS: for a non-zero-length file opened with fopen(,
"a+"), ftell(fp) gives 0 not the EOF location.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. gcc ftell.c
3. echo $?
Created attachment 89212 [details]
repro case for ftell bug
See info libc on fopen:
Open or create file for both reading and appending. If the
file exists, its initial contents are unchanged. Otherwise,
a new file is created. The initial file position for reading
is at the beginning of the file, but output is always
appended to the end of the file.
This is a deliberate change in behaviour since glibc 2.2, then?
The fopen man page says "The stream is positioned at the end of the file", so at
least this is a documentation bug.
Yes, it was deliberate change:
2002-08-26 Ulrich Drepper <email@example.com>
* libio/Makefile (tests): Add bug-fopena+.
* libio/bug-fopena+.c: New file.
* libio/fileops.c (_IO_file_open): Only set file pointer to end of the
file for _IO_IS_APPENDING if file isn't opened for reading, too.
This is documented in libc.info, manual pages are hopelessly outdated.
fixed in 1.60-1