Distinguishing a pipe from a file in windows
Question
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.
My question is: given a HANDLE how do you determine what the underlying type is? For example, I have a HANDLE that's either real file, or a named/anonymous pipe. I'd like to know whether PeekNamedPipe can be called on this HANDLE.
Solution
Use GetFileType
. Check for a return value of FILE_TYPE_PIPE
.
http://msdn.microsoft.com/en-us/library/aa364960(VS.85).aspx
OTHER TIPS
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. Its possible to try and fully reverse engineer and re-implement the logic the file system goes through to test the ACLs. Or, just try and open it.