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


Returns operating-system file handle associated with existing low level file descriptor.

long _get_osfhandle( 
   int fd 


User file descriptor.

Return Value

The _get_osfhandle function returns an OS file handle if fd (the low level file descriptor) is in range and if it is internally marked as free. Otherwise it returns INVALID_HANDLE_VALUE (–1) and sets errno to EBADF, indicating an invalid file handle.


Routine Required header Compatibility
_get_osfhandle <io.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.

See Also

File Handling Routines | _close | _creat | _dup | _open | Run-Time Routines and .NET Framework Equivalents

© 2016 Microsoft