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.
_open_osfhandle returns a C run-time file descriptor. Otherwise, it returns -1.
_open_osfhandle function allocates a C run-time file descriptor. It associates this file descriptor with the operating system file handle specified by
osfhandle. To avoid a compiler warning, cast the
osfhandle argument from
flags argument is an integer expression formed from one or more of the manifest constants defined in
<fcntl.h>. You can use the bitwise "or" (
|) operator to combine two or more manifest constants to form the
These manifest constants are defined in
||Positions a file pointer to the end of the file before every write operation.|
||Opens the file for reading only.|
||Opens the file in text (translated) mode.|
||Opens the file in Unicode (translated UTF-16) mode.|
_open_osfhandle call transfers ownership of the Win32 file handle to the file descriptor. To close a file opened by using
_close. The underlying OS file handle is also closed by a call to
_close. Don't call the Win32 function
CloseHandle on the original handle. If the file descriptor is owned by a
FILE * stream, then a call to
fclose closes both the file descriptor and the underlying handle. In this case, don't call
_close on the file descriptor or
CloseHandle on the original handle.
By default, this function's global state is scoped to the application. To change this, see Global state in the CRT.
For more compatibility information, see Compatibility.
Submit and view feedback for