在 Windows/mingw 上,`fcntl(fd, F_GETFL) | 等价于什么? O_ACCMODE`?

发布于 2024-10-10 21:51:10 字数 53 浏览 8 评论 0原文

我正在 Windows 上用 Mingw 编译一个程序。如何获取打开的文件描述符的访问模式?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

音盲 2024-10-17 21:51:11

根据 Win32.hlp,API 在 KERNEL32 中提供了函数 BOOL GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)LPBY_HANDLE_FILE_INFORMATION是一个BY_HANDLE_FILE_INFORMATION*,其中BY_HANDLE_FILE_INFORMATION如下:

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;

调用该函数后,如果返回true,则BY_HANDLE_FILE_INFORMATION code> 包含与您的文件相关的数据。 dwFileAttributes 可能包含 FILE_ATTRIBUTE_READ_ONLY 标志。

如果您想要更多,还有:

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
);

API 参考对于 SECURITY_DESCRIPTOR 的含义必然是模糊的,但您可以使用其地址作为参数来调用一堆其他函数来获取特定属性。 SECURITY_INFORMATION 只是一个 DWORD 常量,指定您计划调用其中哪个函数。您可以在 http://msdn.microsoft 找到更多信息.com/en-us/library/aa446641%28VS.85%29.aspx

编辑 - 第二个代码部分看起来总是很奇怪,但是 API 参考的链接将引导您到达您需要去的地方,如果你稍微挖掘一下。

According to Win32.hlp, the API supplies the function BOOL GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation) in KERNEL32. LPBY_HANDLE_FILE_INFORMATION is a BY_HANDLE_FILE_INFORMATION*, where BY_HANDLE_FILE_INFORMATION is 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 said function, if it returns true, the BY_HANDLE_FILE_INFORMATION contains data pertinent to your file. dwFileAttributes may contain the FILE_ATTRIBUTE_READ_ONLY flag.

If you want more than that, there is 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 reference is necessarily vague on what a SECURITY_DESCRIPTOR is, but you can call a bunch of other functions using its address as a parameter to get specific properties. The SECURITY_INFORMATION is just a DWORD constant specifying which of these functions you plan to call. You can find more info at http://msdn.microsoft.com/en-us/library/aa446641%28VS.85%29.aspx

Edit - the second code section keeps coming out looking screwy, but the link to the API reference will lead you where you need to go if you dig around a bit.

回忆凄美了谁 2024-10-17 21:51:11

据我所知,你不能。

https: //web.archive.org/web/20161107234935/http://www.zemris.fer.hr/predmeti/os1/misc/Unix2Win.htm 是 unix 到 windows 移植的一个很好的指南。

也许您可以使用 Cygwin POSIX“仿真”?

As far as I can tell, you cant.

https://web.archive.org/web/20161107234935/http://www.zemris.fer.hr/predmeti/os1/misc/Unix2Win.htm is a good guide for unix-to-windows porting.

Maybe you could use the Cygwin POSIX "emulation"?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文