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


Associates a C run-time file descriptor with an existing operating-system file handle.

int _open_osfhandle (
   intptr_t osfhandle,
   int flags 


Operating-system file handle.
Types of operations allowed.

Return Value

If successful, _open_osfhandle returns a C run-time file descriptor. Otherwise, it returns –1.


The _open_osfhandle function allocates a C run-time file descriptor and associates it with the operating-system file handle specified by osfhandle. The flags argument is an integer expression formed from one or more of the manifest constants defined in FCNTL.H. When two or more manifest constants are used to form the flags argument, the constants are combined with the bitwise-OR operator ( | ).

The FCNTL.H file defines the following manifest constants:

Positions file pointer to end of file before every write operation.
Opens file for reading only.
Opens file in text (translated) mode.


Routine Required header Compatibility
_open_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 | Run-Time Routines and .NET Framework Equivalents

© 2015 Microsoft