Operating systems, development tools, and professional services
for connected embedded systems
for connected embedded systems
![]() |
![]() |
![]() |
![]() |
eof()
Test if the end-of-file has been reached
Synopsis:
#include <unistd.h> int eof( int filedes );
Arguments:
- filedes
- A file descriptor for the file that you want to check.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The eof() function is a low-level function that determines if the end of the file specified by filedes has been reached.
Input operations set the current file position; you can call the eof() function to detect the end of the file before more input operations to prevent attempts at reading beyond the end of the file.
Returns:
- 1
- The end-of-file has been reached.
- 0
- The end-of-file hasn't been reached.
- -1
- An error occurred (errno is set).
Errors:
- EBADF
- The file descriptor, filedes, isn't valid.
Examples:
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main( void )
{
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 );
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
Classification:
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |
See also:
![]() |
![]() |
![]() |
![]() |

![[Previous]](../prev.gif)
![[Contents]](../contents.gif)
![[Index]](../keyword_index.gif)
![[Next]](../next.gif)