On Windows / mingw, which is equivalent to `fcntl (fd, F_GETFL) | O_ACCMODE`?

I am compiling a program on Windows with Mingw. How can I get the access mode for the open file descriptor?

+7
c windows file-descriptor mingw
source share
2 answers

According to Win32.hlp, the API provides the BOOL GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation) function BOOL GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation) in KERNEL32. LPBY_HANDLE_FILE_INFORMATION is BY_HANDLE_FILE_INFORMATION* , where BY_HANDLE_FILE_INFORMATION as follows:

 typedef struct _BY_HANDLE_FILE_INFORMATION { // bhfi DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD dwVolumeSerialNumber; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD nNumberOfLinks; DWORD nFileIndexHigh; DWORD nFileIndexLow; } BY_HANDLE_FILE_INFORMATION; 

After calling the specified function, if it returns true, BY_HANDLE_FILE_INFORMATION contains data related to your file. dwFileAttributes may contain the FILE_ATTRIBUTE_READ_ONLY flag.

If you want more of this, there are also:

 BOOL GetKernelObjectSecurity( HANDLE Handle, // handle of object to query SECURITY_INFORMATION RequestedInformation, // requested information PSECURITY_DESCRIPTOR pSecurityDescriptor, // address of security descriptor DWORD nLength, // size of buffer for security descriptor LPDWORD lpnLengthNeeded // address of required size of buffer ); 

The API link is necessarily vague as to what SECURITY_DESCRIPTOR , but you can call a bunch of other functions using your address as a parameter to get specific properties. SECURITY_INFORMATION is simply a DWORD constant that determines which of these functions you plan to call. You can find more information at http://msdn.microsoft.com/en-us/library/aa446641%28VS.85%29.aspx

Edit - the second section of the code continues to fail, but the link to the API link takes you where you need to go if you dig a little.

+2
source share

As far as I can tell, you cannot.

https://web.archive.org/web/20161107234935/http://www.zemris.fer.hr/predmeti/os1/misc/Unix2Win.htm is a good guide to porting from Unix to Windows.

Maybe you could use Cygwin POSIX "emulation"?

0
source share

All Articles