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): glibc-2.2.93-5 How reproducible: Always Steps to Reproduce: 1. gcc ftell.c 2. ./a.out 3. echo $? Actual results: 1 Expected results: 0 Additional info:
Created attachment 89212 [details] repro case for ftell bug
See info libc on fopen: `a+' 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 <drepper> * 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