fseek fread fwrite fflush

Rahul Dhesi dhesi%cirrusl at oliveb.ATC.olivetti.com
Tue Apr 16 05:32:19 AEST 1991


Somebody writes:

     Certainly, a fflush() before a close is redundant.

Peculiar counterexample follows.

In an MS-DOS environment, to set the timestamp on a file, you must
first open it and get a file descriptor (file handle) to it.  So, if
you have just finished writing data to an open file and want to leave
its timestamp set to some special value, the safe sequence is:

     if (fflush(f) != 0) {
	handle error;
     }
     set_timestamp(fileno(f), time_value);
     (void) fclose(f);

If the fflush is not done, the fclose can write data to the file,
overriding the timestamp that has been set.
--
Rahul Dhesi <dhesi at cirrus.COM>
UUCP:  oliveb!cirrusl!dhesi



More information about the Comp.lang.c mailing list