在 Windows/mingw 上,`fcntl(fd, F_GETFL) | 等价于什么? O_ACCMODE`?
我正在 Windows 上用 Mingw 编译一个程序。如何获取打开的文件描述符的访问模式?
I am compiling a program on Windows with Mingw. How can I get the access mode for an open file descriptor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据 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
如下:调用该函数后,如果返回true,则
BY_HANDLE_FILE_INFORMATION
code> 包含与您的文件相关的数据。dwFileAttributes
可能包含FILE_ATTRIBUTE_READ_ONLY
标志。如果您想要更多,还有:
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 aBY_HANDLE_FILE_INFORMATION*
, whereBY_HANDLE_FILE_INFORMATION
is as follows:After calling said function, if it returns true, the
BY_HANDLE_FILE_INFORMATION
contains data pertinent to your file.dwFileAttributes
may contain theFILE_ATTRIBUTE_READ_ONLY
flag.If you want more than that, there is also:
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. TheSECURITY_INFORMATION
is just aDWORD
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.aspxEdit - 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.
据我所知,你不能。
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"?