eof


Description:

[ CCode ( cname = "feof" ) ]
public bool eof ()

Checks if the end of the given file stream has been reached.

This function only reports the stream state as reported by the most recent I/O operation, it does not examine the associated data source. For example, if the most recent I/O was a GLib.FileStream.getc, which returned the last byte of a file, GLib.FileStream.eof returns non-zero. The next GLib.FileStream.getc fails and changes the stream state to end-of-file. Only then feof returns zero.

In typical usage, input stream processing stops on any error; GLib.FileStream.eof and GLib.FileStream.error are then used to distinguish between different error conditions.

Example: Check if the end of file has been reached:

public static int main (string[] args) {
FileStream stream = FileStream.open (args[0], "rb");
assert (stream != null);
int cnt = 0;

for (cnt = 0; stream.eof () == false; stream.getc (), cnt++);
print ("%d\n", cnt);

return 0;
}

valac --pkg glib-2.0 GLib.FileStream.eof.vala