[project @ 2001-11-26 16:37:33 by sof]
authorsof <unknown>
Mon, 26 Nov 2001 16:37:33 +0000 (16:37 +0000)
committersof <unknown>
Mon, 26 Nov 2001 16:37:33 +0000 (16:37 +0000)
fdType: clarify that this op will fail with non-file handles/descriptors
        under Win32.

ghc/lib/std/PrelPosix.hsc

index c6b09f5..5d85f61 100644 (file)
@@ -1,7 +1,6 @@
 {-# OPTIONS -fno-implicit-prelude #-}
 
 -- ---------------------------------------------------------------------------
--- $Id: PrelPosix.hsc,v 1.14 2001/09/26 10:35:41 simonmar Exp $
 --
 -- POSIX support layer for the standard libraries
 --
@@ -78,17 +77,19 @@ fdFileSize fd =
 data FDType  = Directory | Stream | RegularFile
               deriving (Eq)
 
+-- NOTE: On Win32 platforms, this will only work with file descriptors
+-- referring to file handles. i.e., it'll fail for socket FDs.
 fdType :: Int -> IO FDType
 fdType fd = 
   allocaBytes (#const sizeof(struct stat)) $ \ p_stat -> do
-    throwErrnoIfMinus1Retry "fileSize" $
+    throwErrnoIfMinus1Retry "fdType" $
        c_fstat (fromIntegral fd) p_stat
     c_mode <- (#peek struct stat, st_mode) p_stat :: IO CMode
     case () of
       _ | s_isdir c_mode                    -> return Directory
         | s_isfifo c_mode || s_issock c_mode -> return Stream
-       | s_isreg c_mode                     -> return RegularFile
-       | otherwise                          -> ioException ioe_unknownfiletype
+        | s_isreg c_mode                    -> return RegularFile
+        | otherwise                         -> ioException ioe_unknownfiletype
 
 ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"
                        "unknown file type" Nothing