Return the file descriptor for a stream
#include <stdio.h> int fileno( FILE * stream );
libc
The fileno() function returns the file descriptor for the specified file stream. This file descriptor can be used in POSIX input/output calls anywhere the value returned by open() can be used.
| In QNX, the file descriptor is also the connection ID (coid) used by various QNX-specific functions. |
The following symbolic values in <unistd.h> define the file descriptors associated with the C language stdin, stdout, and stderr streams:
A file descriptor for success, or -1 if an error occurs (errno is set).
#include <stdlib.h>
#include <stdio.h>
int main( void )
{
FILE *stream;
stream = fopen( "file", "r" );
if( stream != NULL ) {
printf( "File number is %d.\n", fileno( stream ) );
fclose( stream );
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
Produces output similar to:
File number is 7.
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |