This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]