ioe_closedHandle, ioe_EOF, ioe_notReadable, ioe_notWritable,
stdin, stdout, stderr,
- IOMode(..), IOModeEx(..), openFile, openFileEx, openFd,
+ IOMode(..), IOModeEx(..), openFile, openFileEx, openFd, fdToHandle,
hFileSize, hIsEOF, isEOF, hLookAhead, hSetBuffering, hSetBinaryMode,
hFlush,
implementation is free to impose stricter conditions.
-}
-data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode
- deriving (Eq, Ord, Ix, Enum, Read, Show)
-
data IOModeEx
= BinaryMode IOMode
| TextMode IOMode
mkFileHandle fd is_stream filepath ha_type binary
+fdToHandle :: FD -> IO Handle
+fdToHandle fd = do
+ mode <- fdGetMode fd
+ let fd_str = "<file descriptor: " ++ show fd ++ ">"
+ openFd fd Nothing fd_str mode True{-bin mode-} False{-no truncate-}
+
foreign import ccall unsafe "lockFile"
lockFile :: CInt -> CInt -> CInt -> IO CInt
module GHC.IOBase where
import GHC.ST
+import GHC.Arr -- to derive Ix class
+import GHC.Enum -- to derive Enum class
import GHC.STRef
import GHC.Base
import GHC.Num -- To get fromInteger etc, needed because of -fno-implicit-prelude
(case fn of
Nothing -> id
Just name -> showString "\nFile: " . showString name)
+
+-- -----------------------------------------------------------------------------
+-- IOMode type
+
+data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode
+ deriving (Eq, Ord, Ix, Enum, Read, Show)
\end{code}
c_closesocket :: CInt -> IO CInt
#endif
+fdGetMode :: Int -> IO IOMode
+fdGetMode fd = do
+ flags <- throwErrnoIfMinus1Retry "fdGetMode"
+ (c_fcntl_read (fromIntegral fd) const_f_getfl)
+
+ let
+ wH = (flags .&. o_WRONLY) /= 0
+ aH = (flags .&. o_APPEND) /= 0
+ rwH = (flags .&. o_RDWR) /= 0
+
+ mode
+ | wH && aH = AppendMode
+ | wH = WriteMode
+ | rwH = ReadWriteMode
+ | otherwise = ReadMode
+
+ return mode
+
-- ---------------------------------------------------------------------------
-- Terminal-related stuff
/* -----------------------------------------------------------------------------
- * $Id: HsBase.h,v 1.10 2002/07/17 09:22:20 simonmar Exp $
+ * $Id: HsBase.h,v 1.11 2002/08/29 11:49:11 simonmar Exp $
*
* (c) The University of Glasgow 2001-2002
*
/* in system.c */
HsInt systemCmd(HsAddr cmd);
+/* in rawSystem.c */
+HsInt rawSystemCmd(HsAddr cmd);
+
/* in inputReady.c */
int inputReady(int fd, int msecs, int isSock);
#endif
+INLINE int __hscore_hs_fileno (FILE *f) { return fileno (f); }