Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract file HANDLE from Windows file descriptor or from FILE*

Tags:

file-io

winapi

Is it possible to extract file HANDLE from Windows file descriptor or from FILE* ?

As an example, FILE* is implemeted on top of file descriptors, and in turn file descriptors are implemented (on Windows) on top of HANDLEs. A FD can be extracted from FILE* using documented fileno() function. Extracting HANDLE from FD might be more hacking or more documented ....

like image 656
Andrei Avatar asked Oct 12 '11 20:10

Andrei


People also ask

What is the difference between file descriptor and file handle?

From what I have gathered from Wikipedia, a file descriptor is an index in a file descriptor table, which points to a file name in a file table, which in turn points to an inode in an inode table. File handle is a type of data structure that stores a file descriptor.

How to Find open handles on a file in Windows?

Microsoft/SysInternals Process Explorer - Go to Find > Find Handle or DLL. In the "Handle or DLL substring:" text box, type the path to the file (e.g. "C:\path\to\file. txt") and click "Search". All processes which have an open handle to that file should be listed.

What is file handle in Windows?

The file handle is used to identify the file in many function calls. Each file handle and file object is generally unique to each process that opens a file—the only exceptions to this are when a file handle held by a process is duplicated, or when a child process inherits the file handles of the parent process.

Does Windows use file descriptor?

File descriptors were first used in Unix, and are used by modern operating systems including Linux, macOS, and BSD. In Microsoft Windows, file descriptors are known as file handles.


1 Answers

Yes. See the _get_osfhandle function.

like image 147
Ben Voigt Avatar answered Oct 01 '22 03:10

Ben Voigt