eof

determine if the end-of-file has been reached

Synopsis:

#include <unistd.h>
int eof( int filedes );

Description:

The eof() function determines, at the operating system level, if the end of the file has been reached for the file whose file descriptor is given by filedes. Because the current file position is set following an input operation, the eof() function can be called to detect the end of the file before an input operation beyond the end of the file is attempted.

Returns:

1
the current file position is at the end of the file
0
the current file position is not at the end
-1
an error occurred; in this case errno is set to indicate the error.

Errors:

EBADF
The filedes argument is not a valid file descriptor.

See also:

errno, read()

Examples:

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>

void main()
  {
    int filedes , len;
    char buffer[100];

    filedes = open( "file", O_RDONLY );
    if( filedes != -1 ) {
      while( ! eof( filedes ) ) {
        len = read( filedes , buffer, sizeof(buffer) - 1 );
        buffer[ len ] = '\0';
        printf( "%s", buffer );
      }
      close( filedes );
    }
  }

Classification:

WATCOM

Systems:

All (except DOS/PM)