_fileno

Gets the file handle associated with a stream.

int _fileno( FILE *stream );

Function Required Header Compatibility
_fileno <stdio.h> Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

_fileno returns the file handle. There is no error return. The result is undefined if stream does not specify an open file.

Parameter

stream

Pointer to FILE structure

Remarks

The _fileno routine returns the file handle currently associated with stream. This routine is implemented both as a function and as a macro. For details on choosing either implementation, see Choosing Between Functions and Macros.

Example

/* FILENO.C: This program uses _fileno to obtain
 * the file handle for some standard C streams.
 */

#include <stdio.h>

void main( void )
{
   printf( "The file handle for stdin is %d\n", _fileno( stdin ) );
   printf( "The file handle for stdout is %d\n", _fileno( stdout ) );
   printf( "The file handle for stderr is %d\n", _fileno( stderr ) );
}

Output

The file handle for stdin is 0
The file handle for stdout is 1
The file handle for stderr is 2

Stream I/O Routines

See Also   _fdopen, _filelength, fopen, freopen