gtpc2m2f | C/C++ Language Support User's Guide |
This function writes buffer to a file.
Format
#include <stdio.h> int fflush(FILE *stream);
This function flushes any buffered data written to the stream pointed to by stream. If stream is NULL, it flushes all streams that are open for writing, and all streams that are open for updating that have data buffered for output. There is no effect on streams that are opened for reading or updating if the last operation on the stream was not a write.
The buffering mode and the file type can have an effect on when output data is flushed.
The stream remains open after the fflush function call. If stream is open for update, a read operation can immediately follow the fflush function call.
Normal Return
If successful, the fflush function returns a value 0.
Error Return
The fflush function returns EOF if an error occurs. When flushing all open files, a failure to flush any of the files causes EOF to be returned. However, flushing will continue on any other open files that can be flushed successfully.
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Examples
The following example flushes a stream buffer and tests for the returned value of 0 to see if the flushing was successful.
#include <stdio.h> int retval; int main(void) { FILE *stream; stream = fopen("myfile.dat", "w"); retval=fflush(stream); printf("return value=%i",retval); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.