Return the file descriptor for a stream
#include <stdio.h> int fileno( FILE * stream );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
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.
To associate a stream with a file descriptor, call fdopen().
The following symbolic values in <unistd.h> define the file descriptors associated with the C language stdin, stdout, and stderr streams:
A file descriptor, 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; }
This program produces output similar to:
File number is 7.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |