简体   繁体   English

在Windows中将管道与文件区别开

[英]Distinguishing a pipe from a file in windows

On Unix, everything is a file, so you can use file i/o functions with pipes, files, sockets, etc. But on windows, the api you use depends on the type of i/o HANDLE you have. 在Unix上,所有内容都是文件,因此您可以将文件I / O函数与管道,文件,套接字等一起使用。但是在Windows上,您使用的api取决于您拥有的I / O HANDLE的类型。

My question is: given a HANDLE how do you determine what the underlying type is? 我的问题是:给定HANDLE,您如何确定底层类型是什么? For example, I have a HANDLE that's either real file, or a named/anonymous pipe. 例如,我有一个HANDLE,它是真实文件或命名/匿名管道。 I'd like to know whether PeekNamedPipe can be called on this HANDLE. 我想知道是否可以在此HANDLE上调用PeekNamedPipe。

Use GetFileType . 使用GetFileType Check for a return value of FILE_TYPE_PIPE . 检查返回值FILE_TYPE_PIPE

http://msdn.microsoft.com/en-us/library/aa364960(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa364960(VS.85).aspx

Without trying to be silly. 不要试图变得愚蠢。 Call it. 称它为。 If you get an error code back saying its the wrong type of thing... then you know. 如果您收到一个错误代码,说出它的错误类型,那么您知道。

A similar principal is relevent when trying to see if the user has the rights to open a file. 尝试查看用户是否有权打开文件时,类似的主体是relevent。 Its possible to try and fully reverse engineer and re-implement the logic the file system goes through to test the ACLs. 可以尝试完全反向工程并重新实现文件系统测试ACL的逻辑。 Or, just try and open it. 或者,只需尝试打开它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM