fclearerr#

Purpose#

Gets the error status of a file, then clears it.

Format#

err = fclearerr(fh)#
Parameters:

fh (scalar) – file handle of a file opened with fopen().

Returns:

err (scalar) – error status equal to 1 if there has been a read or write error on a file, 0 otherwise.

Remarks#

Each file has an error flag that gets set when there is an I/O error on the file. Typically, once this flag is set, you can no longer do I/O on the file, even if the error is a recoverable one. fclearerr() clears the file’s error flag, so you can attempt to continue using it.

If you pass fclearerr() the handle of a file opened with open (i.e., a dataset or matrix file), your program will terminate with a fatal error.

The flag accessed by fclearerr() is not the same as that accessed by fstrerror().

Example#

// Open a file and check its error status
fname = tempname("/tmp", "ex", ".txt");
fh = fopen(fname, "w");
call fputs(fh, "test data");
call close(fh);

fh = fopen(fname, "r");
err = fclearerr(fh);
print "Error status (0=none):" err;
call close(fh);