Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 81359

Summary: after fopen(, "a+") ftell() gives 0 not EOF
Product: [Retired] Red Hat Linux Reporter: Joe Orton <jorton>
Component: man-pagesAssignee: Eido Inoue <havill>
Status: CLOSED RAWHIDE QA Contact: Ben Levenson <benl>
Severity: medium Docs Contact:
Priority: low    
Version: 8.0CC: mitr
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: 1.60-1 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2003-08-28 20:31:44 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---
Attachments:
Description Flags
repro case for ftell bug none

Description Joe Orton 2003-01-08 15:01:51 UTC
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:

Comment 1 Joe Orton 2003-01-08 15:02:54 UTC
Created attachment 89212 [details]
repro case for ftell bug

Comment 2 Jakub Jelinek 2003-01-20 18:20:14 UTC
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.

Comment 3 Joe Orton 2003-01-21 09:33:09 UTC
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.

Comment 4 Jakub Jelinek 2003-01-21 09:51:31 UTC
Yes, it was deliberate change:
2002-08-26  Ulrich Drepper  <drepper@redhat.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.

Comment 5 Eido Inoue 2003-08-28 20:31:44 UTC
fixed in 1.60-1