Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer


Gets the file descriptor associated with a stream.

int _fileno( 
   FILE *stream 


Pointer to FILE structure.

Return Value

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


The _fileno routine returns the file descriptor 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.


Function Required header Compatibility
_fileno <stdio.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


// crt_fileno.c
/* This program uses _fileno to obtain
 * the file descriptor for some standard C streams.

#include <stdio.h>

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


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

See Also

Stream I/O Routines | _fdopen | _filelength | fopen | freopen | Run-Time Routines and .NET Framework Equivalents

© 2016 Microsoft