[Bug stdio/16680] New: ftell does not give the correct output for append mode files after a rewind

siddhesh at redhat dot com sourceware-bugzilla@sourceware.org
Mon Mar 10 11:46:00 GMT 2014


https://sourceware.org/bugzilla/show_bug.cgi?id=16680

            Bug ID: 16680
           Summary: ftell does not give the correct output for append mode
                    files after a rewind
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: siddhesh at redhat dot com
          Reporter: siddhesh at redhat dot com

ftell continues to (incorrectly) return the end of the file as the current
position for files opened in any of the append modes when the file stream is
rewound, instead of returning the offset as 0.

To reproduce:

#include <stdio.h>
#include <string.h>

const char *data = "qwertyuioplkjhgfdsazxcvbnm";

int
main ()
{
  FILE *stream = fopen("/tmp/foo.out", "a");
  long pos = ftell(stream);  // pos is zero as expected
  fwrite(data, 1, strlen (data) + 1, stream);
  pos = ftell(stream);  // pos is the length of the written string
  printf ("ftell: %ld\n", pos);
  rewind(stream);
  pos = ftell(stream);  // FAILURE happens here, pos is not zero
  printf ("ftell: %ld\n", pos);
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.



More information about the Glibc-bugs mailing list