fileno -- Determine File Handle

Format

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

Language Level: XPG4, Extension
fileno determines the file handle currently associated with stream.

Note: In earlier releases of the C/C++ run-time library, fileno began with an underscore (_fileno). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, IBM C and C++ Compilers will map _fileno to fileno for you.

Return Value
fileno returns the file handle. If the function fails, the return value is -1 and the errno variable may be set to one of the following values:

Value Meaning
ENULLFCB The input stream is NULL.
EBADTYPE The input stream file is not a stream file.

The result is undefined if stream does not specify an open file.

Example
This example determines the file handle of the stderr data stream.

#include <stdio.h>
int main(void)
{
   int result;
   result = 0xFFFF&fileno(stderr);
   printf("The file handle associated with stderr is %d.\n", result);
   return 0;
   /*****************************************************************
      The output should be similar to:
      The file handle associated with stderr is 2.
   *****************************************************************/
}


dup -- Associate Second Handle with Open File
dup2 -- Associate Second Handle wirh Open File
fopen -- Open Files
freopen -- Redirect Open Files
isatty -- Test Handle for Character Device
open -- Open File
<stdio.h>