fileno

return the number of the file descriptor for a stream

Synopsis:

#include <stdio.h>
int fileno( FILE *stream );

Description:

The fileno() function returns the number of the file descriptor for the file designated by stream. This number can be used in POSIX input/output calls anywhere the value returned by open() can be used. The following symbolic values in unistd.h define the file descriptors that are associated with the C language stdin, stdout, and stderr files when the application is started.

STDIN_FILENO
Standard input file number, stdin (0)
STDOUT_FILENO
Standard output file number, stdout (1)
STDERR_FILENO
Standard error file number, stderr (2)

Returns:

The fileno() function returns the number of the file descriptor for the file designated by stream. If an error occurs, a value of -1 is returned, and errno is set to indicate the error.

See also:

errno, open()

Examples:

#include <stdio.h>

void main()
  {
    FILE *stream;

    stream = fopen( "file", "r" );
    printf( "File number is %d\n", fileno( stream ) );
    fclose( stream );
  }

produces output similar to the following:

File number is 7

Classification:

POSIX 1003.1

Systems:

All (except DOS/PM)