Bug 81359 - after fopen(, "a+") ftell() gives 0 not EOF
Summary: after fopen(, "a+") ftell() gives 0 not EOF
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: man-pages
Version: 8.0
Hardware: i386
OS: Linux
low
medium
Target Milestone: ---
Assignee: Eido Inoue
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-01-08 15:01 UTC by Joe Orton
Modified: 2007-03-27 03:59 UTC (History)
1 user (show)

Fixed In Version: 1.60-1
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2003-08-28 20:31:44 UTC
Embargoed:


Attachments (Terms of Use)
repro case for ftell bug (386 bytes, patch)
2003-01-08 15:02 UTC, Joe Orton
no flags Details | Diff

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>

        * 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


Note You need to log in before you can comment on or make changes to this bug.