_fileno

Description

Gets the file handle associated with a stream.

#include <stdio.h>

int _fileno( FILE *stream );

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.

Return Value

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

Compatibility

Standards:UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

Use _fileno for compatibility with ANSI naming conventions of non-ANSI functions. Use fileno and link with OLDNAMES.LIB for UNIX compatibility.

See Also

_fdopen, _filelength, fopen, freopen

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