{-# OPTIONS -fno-implicit-prelude -optc-DNON_POSIX_SOURCE #-}
-- ---------------------------------------------------------------------------
--- $Id: PrelPosix.hsc,v 1.5 2001/05/30 16:39:22 sewardj Exp $
+-- $Id: PrelPosix.hsc,v 1.10 2001/08/10 11:02:00 simonmar Exp $
--
-- POSIX support layer for the standard libraries
--
ioe_unknownfiletype = IOError Nothing UnsupportedOperation "fdType"
"unknown file type" Nothing
-foreign import "s_isreg_wrap" s_isreg :: CMode -> Bool
+foreign import "s_isreg_wrap" unsafe s_isreg :: CMode -> Bool
#def inline int s_isreg_wrap(m) { return S_ISREG(m); }
-foreign import "s_isdir_wrap" s_isdir :: CMode -> Bool
+foreign import "s_isdir_wrap" unsafe s_isdir :: CMode -> Bool
#def inline int s_isdir_wrap(m) { return S_ISDIR(m); }
-foreign import "s_isfifo_wrap" s_isfifo :: CMode -> Bool
+foreign import "s_isfifo_wrap" unsafe s_isfifo :: CMode -> Bool
#def inline int s_isfifo_wrap(m) { return S_ISFIFO(m); }
#ifndef mingw32_TARGET_OS
-foreign import "s_issock_wrap" s_issock :: CMode -> Bool
+foreign import "s_issock_wrap" unsafe s_issock :: CMode -> Bool
#def inline int s_issock_wrap(m) { return S_ISSOCK(m); }
#else
s_issock :: CMode -> Bool
s_issock cmode = False
#endif
+
+-- It isn't clear whether ftruncate is POSIX or not (I've read several
+-- manpages and they seem to conflict), so we truncate using open/2.
+fileTruncate :: FilePath -> IO ()
+fileTruncate file = do
+ let flags = o_WRONLY .|. o_TRUNC
+ withCString file $ \file_cstr -> do
+ fd <- fromIntegral `liftM`
+ throwErrnoIfMinus1Retry "fileTruncate"
+ (c_open file_cstr (fromIntegral flags) 0o666)
+ c_close fd
+ return ()
+
-- ---------------------------------------------------------------------------
-- Terminal-related stuff
foreign import "write" unsafe
c_write :: CInt -> Ptr CChar -> CSize -> IO CSsize
+foreign import "read" unsafe
+ c_read :: CInt -> Ptr CChar -> CSize -> IO CSsize
+
#ifndef mingw32_TARGET_OS
foreign import "fcntl" unsafe
fcntl_read :: CInt -> CInt -> IO CInt
foreign import "fork" unsafe
fork :: IO CPid
-foreign import "read" unsafe
- c_read :: CInt -> Ptr CChar -> CSize -> IO CSsize
-
foreign import "sigemptyset" unsafe
c_sigemptyset :: Ptr CSigset -> IO ()
foreign import "tcsetattr" unsafe
c_tcsetattr :: CInt -> CInt -> Ptr Termios -> IO CInt
+foreign import "unlink" unsafe
+ c_unlink :: CString -> IO CInt
+
foreign import "waitpid" unsafe
c_waitpid :: CPid -> Ptr CInt -> CInt -> IO CPid
#endif