determine if the end-of-file has been reached
#include <unistd.h> int eof( int filedes );
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.
#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 ); } }
WATCOM
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes, but modifies errno |
Thread | Yes |