fopen with "a+" does not respect setting file read position to start of file

Brebner, Gavin gavin.brebner@hp.com
Thu Apr 1 09:10:00 GMT 2010


We hit a problem in a code, and narrowed it down to a test case that does :

  while (cnt) {
    f=fopen(host_file, "a+");
    if (!f)
      perror("dup_host_file: Could not open hostfile");
    /* rewind(f); */
    while (cnt) {
      int ret=fscanf(f, "%s", line);
      if (ret != EOF) {
	  fprintf(f, "%s\n", line);
	  cnt--;
	  dup++;
	}
    }
    fclose(f);

In earlier versions of cygwin we have, this works fine, however in the recently installed 
versions, it no longer works. It seems that fopen(host_file, "a+") is NOT positioning the
read position at the start of the file as it should. Adding an explicit rewind(f) is a 
work around.

Gavin


cygcheck output attached.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cygcheck.out
Type: application/octet-stream
Size: 42374 bytes
Desc: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20100401/8fb97d9f/attachment.obj>
-------------- next part --------------
--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


More information about the Cygwin mailing list