packages feed

unix 2.7.1.0 → 2.7.2.0

raw patch · 51 files changed

+764/−704 lines, 51 filesdep +unbuildabledep ~basePVP ok

version bump matches the API change (PVP)

Dependencies added: unbuildable

Dependency ranges changed: base

API changes (from Hackage documentation)

+ System.Posix.Signals: infixr 9 `deleteSignal`

Files

System/Posix.hs view
@@ -1,18 +1,16 @@ {-# LANGUAGE CPP #-}-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Safe #-}-#endif ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (requires POSIX) ----- POSIX support+-- <http://pubs.opengroup.org/onlinepubs/9699919799/ POSIX.1-2008> support -- ----------------------------------------------------------------------------- @@ -62,7 +60,7 @@ each header file defined by the standard, we categorise its functionality as - - "supported" + - "supported"     Full equivalent functionality is provided by the specified Haskell    module.@@ -71,7 +69,7 @@     The functionality is not currently provided. - - "to be supported" + - "to be supported"     Currently unsupported, but support is planned for the future. @@ -133,17 +131,17 @@ aio.h assert.h complex.h-cpio.h -ctype.h +cpio.h+ctype.h fenv.h float.h fmtmsg.h fnmatch.h ftw.h glob.h-iconv.h -inttypes.h -iso646.h +iconv.h+inttypes.h+iso646.h langinfo.h libgen.h locale.h	(see System.Locale)
System/Posix/ByteString.hs view
@@ -1,18 +1,17 @@ {-# LANGUAGE CPP #-}-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Safe #-}-#endif ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.ByteString -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (requires POSIX) ----- POSIX support with ByteString file paths and environment strings.+-- <http://pubs.opengroup.org/onlinepubs/9699919799/ POSIX.1-2008>+-- support with 'ByteString' file paths and environment strings. -- -- This module exports exactly the same API as "System.Posix", except -- that all file paths and environment strings are represented by
System/Posix/ByteString/FilePath.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif 
System/Posix/Directory.hsc view
@@ -1,5 +1,8 @@+{-# LANGUAGE CApiFFI #-} {-# LANGUAGE NondecreasingIndentation #-}-#ifdef __GLASGOW_HASKELL__+#if __GLASGOW_HASKELL__ >= 709+{-# LANGUAGE Safe #-}+#else {-# LANGUAGE Trustworthy #-} #endif @@ -19,6 +22,11 @@  #include "HsUnix.h" +-- hack copied from System.Posix.Files+#if !defined(PATH_MAX)+# define PATH_MAX 4096+#endif+ module System.Posix.Directory (    -- * Creating and removing directories    createDirectory, removeDirectory,@@ -73,7 +81,7 @@     dirp <- throwErrnoPathIfNullRetry "openDirStream" name $ c_opendir s     return (DirStream dirp) -foreign import ccall unsafe "__hsunix_opendir"+foreign import capi unsafe "HsUnix.h opendir"    c_opendir :: CString  -> IO (Ptr CDir)  -- | @readDirStream dp@ calls @readdir@ to obtain the@@ -116,27 +124,24 @@ -- | @getWorkingDirectory@ calls @getcwd@ to obtain the name --   of the current working directory. getWorkingDirectory :: IO FilePath-getWorkingDirectory = do-  p <- mallocBytes long_path_size-  go p long_path_size-  where go p bytes = do-          p' <- c_getcwd p (fromIntegral bytes)-          if p' /= nullPtr-             then do s <- peekFilePath p'-                     free p'-                     return s-             else do errno <- getErrno-                     if errno == eRANGE-                        then do let bytes' = bytes * 2-                                p'' <- reallocBytes p bytes'-                                go p'' bytes'-                        else throwErrno "getCurrentDirectory"+getWorkingDirectory = go (#const PATH_MAX)+  where+    go bytes = do+        r <- allocaBytes bytes $ \buf -> do+            buf' <- c_getcwd buf (fromIntegral bytes)+            if buf' /= nullPtr+                then do s <- peekFilePath buf+                        return (Just s)+                else do errno <- getErrno+                        if errno == eRANGE+                            -- we use Nothing to indicate that we should+                            -- try again with a bigger buffer+                            then return Nothing+                            else throwErrno "getWorkingDirectory"+        maybe (go (2 * bytes)) return r  foreign import ccall unsafe "getcwd"    c_getcwd   :: Ptr CChar -> CSize -> IO (Ptr CChar)--foreign import ccall unsafe "__hsunix_long_path_size"-  long_path_size :: Int  -- | @changeWorkingDirectory dir@ calls @chdir@ to change --   the current working directory to @dir@.
System/Posix/Directory/ByteString.hsc view
@@ -1,5 +1,8 @@+{-# LANGUAGE CApiFFI #-} {-# LANGUAGE NondecreasingIndentation #-}-#ifdef __GLASGOW_HASKELL__+#if __GLASGOW_HASKELL__ >= 709+{-# LANGUAGE Safe #-}+#else {-# LANGUAGE Trustworthy #-} #endif @@ -19,6 +22,11 @@  #include "HsUnix.h" +-- hack copied from System.Posix.Files+#if !defined(PATH_MAX)+# define PATH_MAX 4096+#endif+ module System.Posix.Directory.ByteString (    -- * Creating and removing directories    createDirectory, removeDirectory,@@ -74,7 +82,7 @@     dirp <- throwErrnoPathIfNullRetry "openDirStream" name $ c_opendir s     return (DirStream dirp) -foreign import ccall unsafe "__hsunix_opendir"+foreign import capi unsafe "HsUnix.h opendir"    c_opendir :: CString  -> IO (Ptr CDir)  -- | @readDirStream dp@ calls @readdir@ to obtain the@@ -117,27 +125,24 @@ -- | @getWorkingDirectory@ calls @getcwd@ to obtain the name --   of the current working directory. getWorkingDirectory :: IO RawFilePath-getWorkingDirectory = do-  p <- mallocBytes long_path_size-  go p long_path_size-  where go p bytes = do-          p' <- c_getcwd p (fromIntegral bytes)-          if p' /= nullPtr-             then do s <- peekFilePath p'-                     free p'-                     return s-             else do errno <- getErrno-                     if errno == eRANGE-                        then do let bytes' = bytes * 2-                                p'' <- reallocBytes p bytes'-                                go p'' bytes'-                        else throwErrno "getCurrentDirectory"+getWorkingDirectory = go (#const PATH_MAX)+  where+    go bytes = do+        r <- allocaBytes bytes $ \buf -> do+            buf' <- c_getcwd buf (fromIntegral bytes)+            if buf' /= nullPtr+                then do s <- peekFilePath buf+                        return (Just s)+                else do errno <- getErrno+                        if errno == eRANGE+                            -- we use Nothing to indicate that we should+                            -- try again with a bigger buffer+                            then return Nothing+                            else throwErrno "getWorkingDirectory"+        maybe (go (2 * bytes)) return r  foreign import ccall unsafe "getcwd"    c_getcwd   :: Ptr CChar -> CSize -> IO (Ptr CChar)--foreign import ccall unsafe "__hsunix_long_path_size"-  long_path_size :: Int  -- | @changeWorkingDirectory dir@ calls @chdir@ to change --   the current working directory to @dir@.
System/Posix/Directory/Common.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif @@ -39,8 +39,8 @@  newtype DirStream = DirStream (Ptr CDir) -type CDir       = ()-type CDirent    = ()+data {-# CTYPE "DIR" #-} CDir+data {-# CTYPE "struct dirent" #-} CDirent  -- | @rewindDirStream dp@ calls @rewinddir@ to reposition --   the directory stream @dp@ at the beginning of the directory.
System/Posix/DynamicLinker.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------
System/Posix/DynamicLinker/ByteString.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif 
System/Posix/DynamicLinker/Common.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------
System/Posix/DynamicLinker/Module.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------
System/Posix/DynamicLinker/Module/ByteString.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif 
System/Posix/DynamicLinker/Prim.hsc view
@@ -1,9 +1,8 @@-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Trustworthy #-} #if __GLASGOW_HASKELL__ >= 709 {-# OPTIONS_GHC -fno-warn-trustworthy-safe #-} #endif-#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.DynamicLinker.Prim@@ -14,8 +13,8 @@ -- Stability   :  provisional -- Portability :  non-portable (requires POSIX) ----- DLOpen and friend---  Derived from GModule.chs by M.Weber & M.Chakravarty which is part of c2hs+-- @dlopen(3)@ and friends+--  Derived from @GModule.chs@ by M.Weber & M.Chakravarty which is part of c2hs. --  I left the API more or less the same, mostly the flags are different. -- -----------------------------------------------------------------------------@@ -45,12 +44,12 @@ import Foreign.C.String ( CString )  --- |On some hosts (e.g. SuSe and Ubuntu Linux) 'RTLD_NEXT' (and--- 'RTLD_DEFAULT') are not visible without setting the macro--- '_GNU_SOURCE'. Since we don't want to define this macro, you can use+-- |On some hosts (e.g. SuSe and Ubuntu Linux) @RTLD_NEXT@ (and+-- @RTLD_DEFAULT@) are not visible without setting the macro+-- @_GNU_SOURCE@. Since we don\'t want to define this macro, you can use -- the function 'haveRtldNext' to check wether the flag `Next` is -- available. Ideally, this will be optimized by the compiler so that it--- should be as efficient as an #ifdef.+-- should be as efficient as an @#ifdef@. -- -- If you fail to test the flag and use it although it is undefined, -- 'packDL' will throw an error.@@ -99,9 +98,9 @@  -- |Flags for 'System.Posix.DynamicLinker.dlsym'. Notice that 'Next' -- might not be available on your particular platform! Use--- `haveRtldNext`.+-- 'haveRtldNext'. ----- If 'RTLD_DEFAULT' is not defined on your platform, `packDL` `Default`+-- If 'RTLD_DEFAULT' is not defined on your platform, 'packDL' 'Default' -- reduces to 'nullPtr'.  data DL = Null | Next | Default | DLHandle (Ptr ()) deriving (Show)
System/Posix/Env.hsc view
@@ -1,6 +1,7 @@+{-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -8,7 +9,7 @@ -- Module      :  System.Posix.Env -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (requires POSIX)@@ -77,9 +78,8 @@       mapM peekFilePath arr  getCEnviron :: IO (Ptr CString)--#if darwin_HOST_OS--- You should not access _environ directly on Darwin in a bundle/shared library.+#if HAVE__NSGETENVIRON+-- You should not access @char **environ@ directly on Darwin in a bundle/shared library. -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html getCEnviron = nsGetEnviron >>= peek @@ -87,7 +87,6 @@    nsGetEnviron :: IO (Ptr (Ptr CString)) #else getCEnviron = peek c_environ_p- foreign import ccall unsafe "&environ"    c_environ_p :: Ptr (Ptr CString) #endif@@ -116,13 +115,21 @@ -- from the environment.  unsetEnv :: String -> IO ()-#ifdef HAVE_UNSETENV-+#if HAVE_UNSETENV+# if !UNSETENV_RETURNS_VOID unsetEnv name = withFilePath name $ \ s ->   throwErrnoIfMinus1_ "unsetenv" (c_unsetenv s) -foreign import ccall unsafe "__hsunix_unsetenv"+-- POSIX.1-2001 compliant unsetenv(3)+foreign import capi unsafe "HsUnix.h unsetenv"    c_unsetenv :: CString -> IO CInt+# else+unsetEnv name = withFilePath name c_unsetenv++-- pre-POSIX unsetenv(3) returning @void@+foreign import capi unsafe "HsUnix.h unsetenv"+   c_unsetenv :: CString -> IO ()+# endif #else unsetEnv name = putEnv (name ++ "=") #endif
System/Posix/Env/ByteString.hsc view
@@ -1,9 +1,8 @@-#ifdef __GLASGOW_HASKELL__+{-# LANGUAGE CApiFFI #-} {-# LANGUAGE Trustworthy #-} #if __GLASGOW_HASKELL__ >= 709 {-# OPTIONS_GHC -fno-warn-trustworthy-safe #-} #endif-#endif  ----------------------------------------------------------------------------- -- |@@ -70,8 +69,8 @@   mapM B.packCString arr  getCEnviron :: IO (Ptr CString)-#if darwin_HOST_OS--- You should not access _environ directly on Darwin in a bundle/shared library.+#if HAVE__NSGETENVIRON+-- You should not access @char **environ@ directly on Darwin in a bundle/shared library. -- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html getCEnviron = nsGetEnviron >>= peek @@ -100,13 +99,21 @@ -- from the environment.  unsetEnv :: ByteString -> IO ()-#ifdef HAVE_UNSETENV-+#if HAVE_UNSETENV+# if !UNSETENV_RETURNS_VOID unsetEnv name = B.useAsCString name $ \ s ->   throwErrnoIfMinus1_ "unsetenv" (c_unsetenv s) -foreign import ccall unsafe "__hsunix_unsetenv"+-- POSIX.1-2001 compliant unsetenv(3)+foreign import capi unsafe "HsUnix.h unsetenv"    c_unsetenv :: CString -> IO CInt+# else+unsetEnv name = B.useAsCString name c_unsetenv++-- pre-POSIX unsetenv(3) returning @void@+foreign import capi unsafe "HsUnix.h unsetenv"+   c_unsetenv :: CString -> IO ()+# endif #else unsetEnv name = putEnv (name ++ "=") #endif
System/Posix/Error.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE CPP #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------
System/Posix/Fcntl.hsc view
@@ -1,7 +1,7 @@ {-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -16,7 +16,7 @@ -- -- POSIX file control support ----- /Since: 2.7.1.0/+-- @since 2.7.1.0 -----------------------------------------------------------------------------  #include "HsUnix.h"@@ -44,7 +44,7 @@ -- -- For more details, see documentation of @posix_fadvise(2)@. ----- /Since: 2.7.1.0/+-- @since 2.7.1.0 data Advice   = AdviceNormal   | AdviceRandom@@ -61,7 +61,7 @@ -- -- (use @#if HAVE_POSIX_FADVISE@ CPP guard to detect availability) ----- /Since: 2.7.1.0/+-- @since 2.7.1.0 fileAdvise :: Fd -> FileOffset -> FileOffset -> Advice -> IO () #if HAVE_POSIX_FADVISE fileAdvise fd off len adv = do@@ -88,7 +88,7 @@ -- -- (use @#if HAVE_POSIX_FALLOCATE@ CPP guard to detect availability). ----- /Since: 2.7.1.0/+-- @since 2.7.1.0 fileAllocate :: Fd -> FileOffset -> FileOffset -> IO () #if HAVE_POSIX_FALLOCATE fileAllocate fd off len = do
System/Posix/Files.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif {-# LANGUAGE CApiFFI #-}@@ -187,7 +187,7 @@       throwErrnoPathIfMinus1_ "getSymbolicLinkStatus" path (c_lstat s p)   return (FileStatus fp) -foreign import ccall unsafe "__hsunix_lstat"+foreign import capi unsafe "HsUnix.h lstat"   c_lstat :: CString -> Ptr CStat -> IO CInt  -- | @createNamedPipe fifo mode@@@ -215,7 +215,7 @@   withFilePath path $ \s ->     throwErrnoPathIfMinus1_ "createDevice" path (c_mknod s mode dev) -foreign import ccall unsafe "__hsunix_mknod"+foreign import capi unsafe "HsUnix.h mknod"   c_mknod :: CString -> CMode -> CDev -> IO CInt  -- -----------------------------------------------------------------------------@@ -347,7 +347,7 @@ -- -- Note: calls @utimensat@ or @utimes@. ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 setFileTimesHiRes :: FilePath -> POSIXTime -> POSIXTime -> IO () #ifdef HAVE_UTIMENSAT setFileTimesHiRes name atime mtime =@@ -368,7 +368,7 @@ -- -- Note: calls @utimensat@ or @lutimes@. ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 setSymbolicLinkTimesHiRes :: FilePath -> POSIXTime -> POSIXTime -> IO () #if HAVE_UTIMENSAT setSymbolicLinkTimesHiRes name atime mtime =@@ -402,7 +402,7 @@ -- -- Note: calls @lutimes@. ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 touchSymbolicLink :: FilePath -> IO () #if HAVE_LUTIMES touchSymbolicLink name =
System/Posix/Files/ByteString.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif {-# LANGUAGE CApiFFI #-}@@ -193,7 +193,7 @@       throwErrnoPathIfMinus1_ "getSymbolicLinkStatus" path (c_lstat s p)   return (FileStatus fp) -foreign import ccall unsafe "__hsunix_lstat"+foreign import capi unsafe "HsUnix.h lstat"   c_lstat :: CString -> Ptr CStat -> IO CInt  -- | @createNamedPipe fifo mode@@@ -221,7 +221,7 @@   withFilePath path $ \s ->     throwErrnoPathIfMinus1_ "createDevice" path (c_mknod s mode dev) -foreign import ccall unsafe "__hsunix_mknod"+foreign import capi unsafe "HsUnix.h mknod"   c_mknod :: CString -> CMode -> CDev -> IO CInt  -- -----------------------------------------------------------------------------
System/Posix/Files/Common.hsc view
@@ -1,6 +1,5 @@-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Trustworthy #-}-#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.Files.Common@@ -83,15 +82,8 @@ import System.Posix.Types import System.IO.Unsafe import Data.Bits-#if defined(HAVE_STRUCT_STAT_ST_CTIM) || \-    defined(HAVE_STRUCT_STAT_ST_MTIM) || \-    defined(HAVE_STRUCT_STAT_ST_ATIM) || \-    defined(HAVE_STRUCT_STAT_ST_ATIMESPEC) || \-    defined(HAVE_STRUCT_STAT_ST_MTIMESPEC) || \-    defined(HAVE_STRUCT_STAT_ST_CTIMESPEC) import Data.Int import Data.Ratio-#endif import Data.Time.Clock.POSIX (POSIXTime) import System.Posix.Internals import Foreign.C@@ -475,7 +467,7 @@ -- -- Note: calls @futimens@ or @futimes@. ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 setFdTimesHiRes :: Fd -> POSIXTime -> POSIXTime -> IO () #if HAVE_FUTIMENS setFdTimesHiRes (Fd fd) atime mtime =@@ -496,7 +488,7 @@ -- -- Note: calls @futimes@. ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 touchFd :: Fd -> IO () #if HAVE_FUTIMES touchFd (Fd fd) =
System/Posix/IO.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -8,7 +8,7 @@ -- Module      :  System.Posix.IO -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (requires POSIX)@@ -63,7 +63,7 @@      -- ** Converting file descriptors to\/from Handles     handleToFd,-    fdToHandle,  +    fdToHandle,    ) where @@ -90,4 +90,4 @@  createFile :: FilePath -> FileMode -> IO Fd createFile name mode-  = openFd name WriteOnly (Just mode) defaultFileFlags{ trunc=True } +  = openFd name WriteOnly (Just mode) defaultFileFlags{ trunc=True }
System/Posix/IO/ByteString.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -8,7 +8,7 @@ -- Module      :  System.Posix.IO.ByteString -- Copyright   :  (c) The University of Glasgow 2002 -- License     :  BSD-style (see the file libraries/base/LICENSE)--- +-- -- Maintainer  :  libraries@haskell.org -- Stability   :  provisional -- Portability :  non-portable (requires POSIX)@@ -63,7 +63,7 @@      -- ** Converting file descriptors to\/from Handles     handleToFd,-    fdToHandle,  +    fdToHandle,    ) where @@ -90,4 +90,4 @@  createFile :: RawFilePath -> FileMode -> IO Fd createFile name mode-  = openFd name WriteOnly (Just mode) defaultFileFlags{ trunc=True } +  = openFd name WriteOnly (Just mode) defaultFileFlags{ trunc=True }
System/Posix/IO/Common.hsc view
@@ -1,7 +1,9 @@-{-# LANGUAGE NondecreasingIndentation, RecordWildCards #-}+{-# LANGUAGE CApiFFI #-}+{-# LANGUAGE NondecreasingIndentation #-}+{-# LANGUAGE RecordWildCards #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif @@ -70,20 +72,13 @@ import Foreign import Foreign.C -#ifdef __GLASGOW_HASKELL__ import GHC.IO.Handle.Internals import GHC.IO.Handle.Types import qualified GHC.IO.FD as FD import qualified GHC.IO.Handle.FD as FD import GHC.IO.Exception import Data.Typeable (cast)-#endif -#ifdef __HUGS__-import Hugs.Prelude (IOException(..), IOErrorType(..))-import qualified Hugs.IO (handleToFd, openFd)-#endif- #include "HsUnix.h"  -- -----------------------------------------------------------------------------@@ -189,7 +184,7 @@                    WriteOnly -> (#const O_WRONLY)                    ReadWrite -> (#const O_RDWR) -foreign import ccall unsafe "__hscore_open"+foreign import capi unsafe "HsUnix.h open"    c_open :: CString -> CInt -> CMode -> IO CInt  -- |Close this file descriptor.  May throw an exception if this is an@@ -211,8 +206,8 @@ -- | Converts an 'Fd' into a 'Handle' that can be used with the -- standard Haskell IO library (see "System.IO"). fdToHandle :: Fd -> IO Handle+fdToHandle fd = FD.fdToHandle (fromIntegral fd) -#ifdef __GLASGOW_HASKELL__ handleToFd h@(FileHandle _ m) = do   withHandle' "handleToFd" h m $ handleToFd' h handleToFd h@(DuplexHandle _ r w) = do@@ -236,19 +231,7 @@      FD.release fd      return (Handle__{haType=ClosedHandle,..}, Fd (FD.fdFD fd)) -fdToHandle fd = FD.fdToHandle (fromIntegral fd)-#endif -#ifdef __HUGS__-handleToFd h = do-  fd <- Hugs.IO.handleToFd h-  return (fromIntegral fd)--fdToHandle fd = do-  mode <- fdGetMode (fromIntegral fd)-  Hugs.IO.openFd (fromIntegral fd) False mode True-#endif- -- ----------------------------------------------------------------------------- -- Fd options @@ -320,9 +303,7 @@     maybeResult (_, (Unlock, _, _, _)) = Nothing     maybeResult x = Just x -type CFLock     = ()--allocaLock :: FileLock -> (Ptr CFLock -> IO a) -> IO a+allocaLock :: FileLock -> (Ptr Base.CFLock -> IO a) -> IO a allocaLock (lockreq, mode, start, len) io =   allocaBytes (#const sizeof(struct flock)) $ \p -> do     (#poke struct flock, l_type)   p (lockReq2Int lockreq :: CShort)@@ -336,7 +317,7 @@ lockReq2Int WriteLock = (#const F_WRLCK) lockReq2Int Unlock    = (#const F_UNLCK) -bytes2ProcessIDAndLock :: Ptr CFLock -> IO (ProcessID, FileLock)+bytes2ProcessIDAndLock :: Ptr Base.CFLock -> IO (ProcessID, FileLock) bytes2ProcessIDAndLock p = do   req   <- (#peek struct flock, l_type)   p   mode  <- (#peek struct flock, l_whence) p
System/Posix/Process.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -22,10 +22,8 @@     -- * Processes      -- ** Forking and executing-#ifdef __GLASGOW_HASKELL__     forkProcess,     forkProcessWithUnmask,-#endif     executeFile,      -- ** Exiting@@ -77,10 +75,6 @@ import System.Posix.Process.Internals import System.Posix.Process.Common import System.Posix.Internals ( withFilePath )--#ifdef __HUGS__-{-# CFILES cbits/HsUnix.c  #-}-#endif  -- | @'executeFile' cmd args env@ calls one of the --   @execv*@ family, depending on whether or not the current
System/Posix/Process/ByteString.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif @@ -23,10 +23,8 @@     -- * Processes      -- ** Forking and executing-#ifdef __GLASGOW_HASKELL__     forkProcess,     forkProcessWithUnmask,-#endif     executeFile,      -- ** Exiting@@ -89,10 +87,6 @@ import qualified Data.ByteString.Char8 as BC  import System.Posix.ByteString.FilePath--#ifdef __HUGS__-{-# CFILES cbits/HsUnix.c  #-}-#endif  -- | @'executeFile' cmd args env@ calls one of the --   @execv*@ family, depending on whether or not the current
System/Posix/Process/Common.hsc view
@@ -1,7 +1,7 @@+{-# LANGUAGE CApiFFI #-} {-# LANGUAGE InterruptibleFFI, RankNTypes #-}-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Trustworthy #-}-#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.Process.Common@@ -21,10 +21,8 @@     -- * Processes      -- ** Forking and executing-#ifdef __GLASGOW_HASKELL__     forkProcess,     forkProcessWithUnmask,-#endif      -- ** Exiting     exitImmediately,@@ -81,16 +79,10 @@ import System.Posix.Types import Control.Monad -#ifdef __GLASGOW_HASKELL__ import Control.Exception.Base ( bracket, getMaskingState, MaskingState(..) ) -- used by forkProcess import GHC.TopHandler   ( runIO ) import GHC.IO ( unsafeUnmask, uninterruptibleMask_ )-#endif -#ifdef __HUGS__-{-# CFILES cbits/HsUnix.c  #-}-#endif- -- ----------------------------------------------------------------------------- -- Process environment @@ -211,9 +203,9 @@                            childSystemTime = cst                           }) -type CTms = ()+data {-# CTYPE "struct tms" #-} CTms -foreign import ccall unsafe "__hsunix_times"+foreign import capi unsafe "HsUnix.h times"   c_times :: Ptr CTms -> IO CClock  -- -----------------------------------------------------------------------------@@ -274,7 +266,6 @@ -- ----------------------------------------------------------------------------- -- Forking, execution -#ifdef __GLASGOW_HASKELL__ {- | 'forkProcess' corresponds to the POSIX @fork@ system call. The 'IO' action passed as an argument is executed in the child process; no other threads will be copied to the child process.@@ -310,11 +301,9 @@  -- | Variant of 'forkProcess' in the style of 'forkIOWithUnmask'. ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 forkProcessWithUnmask :: ((forall a . IO a -> IO a) -> IO ()) -> IO ProcessID forkProcessWithUnmask action = forkProcess (action unsafeUnmask)--#endif /* __GLASGOW_HASKELL__ */  -- ----------------------------------------------------------------------------- -- Waiting for process termination
System/Posix/Process/Internals.hs view
@@ -1,7 +1,5 @@-{-# LANGUAGE CPP #-}-#ifdef __GLASGOW_HASKELL__+{-# LANGUAGE CApiFFI #-} {-# LANGUAGE Trustworthy #-}-#endif  module System.Posix.Process.Internals (        pPrPr_disableITimers, c_execvpe,@@ -21,13 +19,13 @@                             -- signal, the @Bool@ is @True@ if a core                             -- dump was produced                             ---                            -- /Since: 2.7.0.0/+                            -- @since 2.7.0.0    | Stopped Signal         -- ^ the process was stopped by a signal    deriving (Eq, Ord, Show)  -- this function disables the itimer, which would otherwise cause confusing -- signals to be sent to the new process.-foreign import ccall unsafe "pPrPr_disableITimers"+foreign import capi unsafe "Rts.h stopTimer"   pPrPr_disableITimers :: IO ()  foreign import ccall unsafe "__hsunix_execvpe"@@ -56,24 +54,25 @@                         ioError (mkIOError illegalOperationErrorType                                    "waitStatus" Nothing Nothing) -foreign import ccall unsafe "__hsunix_wifexited"++foreign import capi unsafe "HsUnix.h WIFEXITED"   c_WIFEXITED :: CInt -> CInt -foreign import ccall unsafe "__hsunix_wexitstatus"+foreign import capi unsafe "HsUnix.h WEXITSTATUS"   c_WEXITSTATUS :: CInt -> CInt -foreign import ccall unsafe "__hsunix_wifsignaled"+foreign import capi unsafe "HsUnix.h WIFSIGNALED"   c_WIFSIGNALED :: CInt -> CInt -foreign import ccall unsafe "__hsunix_wtermsig"+foreign import capi unsafe "HsUnix.h WTERMSIG"   c_WTERMSIG :: CInt -> CInt -foreign import ccall unsafe "__hsunix_wifstopped"+foreign import capi unsafe "HsUnix.h WIFSTOPPED"   c_WIFSTOPPED :: CInt -> CInt -foreign import ccall unsafe "__hsunix_wstopsig"+foreign import capi unsafe "HsUnix.h WSTOPSIG"   c_WSTOPSIG :: CInt -> CInt -foreign import ccall unsafe "__hsunix_wcoredump"+foreign import capi unsafe "HsUnix.h WCOREDUMP"   c_WCOREDUMP :: CInt -> CInt 
System/Posix/Resource.hsc view
@@ -1,6 +1,7 @@+{-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -55,12 +56,12 @@   | ResourceLimit Integer   deriving Eq -type RLimit = ()+data {-# CTYPE "struct rlimit" #-} RLimit -foreign import ccall unsafe "HsUnix.h __hscore_getrlimit"+foreign import capi unsafe "HsUnix.h getrlimit"   c_getrlimit :: CInt -> Ptr RLimit -> IO CInt -foreign import ccall unsafe "HsUnix.h __hscore_setrlimit"+foreign import capi unsafe "HsUnix.h setrlimit"   c_setrlimit :: CInt -> Ptr RLimit -> IO CInt  getResourceLimit :: Resource -> IO ResourceLimits
System/Posix/Semaphore.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------
System/Posix/SharedMem.hsc view
@@ -1,6 +1,6 @@ #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -35,11 +35,11 @@ import Data.Bits #endif -data ShmOpenFlags = ShmOpenFlags +data ShmOpenFlags = ShmOpenFlags     { shmReadWrite :: Bool,-      -- ^ If true, open the shm object read-write rather than read-only. +      -- ^ If true, open the shm object read-write rather than read-only.       shmCreate :: Bool,-      -- ^ If true, create the shm object if it does not exist. +      -- ^ If true, create the shm object if it does not exist.       shmExclusive :: Bool,       -- ^ If true, throw an exception if the shm object already exists.       shmTrunc :: Bool@@ -54,16 +54,16 @@        cflags1 <- return $ cflags0 .|. (if shmReadWrite flags                                         then #{const O_RDWR}                                         else #{const O_RDONLY})-       cflags2 <- return $ cflags1 .|. (if shmCreate flags then #{const O_CREAT} +       cflags2 <- return $ cflags1 .|. (if shmCreate flags then #{const O_CREAT}                                         else 0)-       cflags3 <- return $ cflags2 .|. (if shmExclusive flags -                                        then #{const O_EXCL} +       cflags3 <- return $ cflags2 .|. (if shmExclusive flags+                                        then #{const O_EXCL}                                         else 0)-       cflags4 <- return $ cflags3 .|. (if shmTrunc flags then #{const O_TRUNC} +       cflags4 <- return $ cflags3 .|. (if shmTrunc flags then #{const O_TRUNC}                                         else 0)        withCAString name (shmOpen' cflags4)     where shmOpen' cflags cname =-              do fd <- throwErrnoIfMinus1 "shmOpen" $ +              do fd <- throwErrnoIfMinus1 "shmOpen" $                        shm_open cname cflags mode                  return $ Fd fd #else
System/Posix/Signals.hsc view
@@ -1,8 +1,6 @@ {-# LANGUAGE CApiFFI, CPP, DeriveDataTypeable, NondecreasingIndentation #-} {-# OPTIONS_GHC -fno-cse #-} -- global variables-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Trustworthy #-}-#endif ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.Signals@@ -66,12 +64,10 @@   signalProcess,   signalProcessGroup, -#ifdef __GLASGOW_HASKELL__   -- * Handling signals   Handler(Default,Ignore,Catch,CatchOnce,CatchInfo,CatchInfoOnce),   SignalInfo(..), SignalSpecificInfo(..),   installHandler,-#endif    -- * Signal sets   SignalSet,@@ -86,14 +82,10 @@    -- * Waiting for signals   getPendingSignals,-#ifndef cygwin32_HOST_OS   awaitSignal,-#endif -#ifdef __GLASGOW_HASKELL__   -- * The @NOCLDSTOP@ flag   setStoppedChildFlag, queryStoppedChildFlag,-#endif    -- MISSING FUNCTIONALITY:   -- sigaction(), (inc. the sigaction structure + flags etc.)@@ -116,11 +108,9 @@ import System.Posix.Process.Internals import Data.Dynamic -#ifdef __GLASGOW_HASKELL__ ##include "rts/Signals.h"  import GHC.Conc hiding (Signal)-#endif  -- ----------------------------------------------------------------------------- -- Specific signals@@ -300,7 +290,10 @@ raiseSignal :: Signal -> IO () raiseSignal sig = throwErrnoIfMinus1_ "raiseSignal" (c_raise sig) -#if defined(__GLASGOW_HASKELL__) && (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(darwin_HOST_OS))+-- See also note in GHC's rts/RtsUtils.c+-- This is somewhat fragile because we need to keep the+-- `#if`-conditional in sync with GHC's runtime.+#if (defined(openbsd_HOST_OS) || defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) || defined(darwin_HOST_OS)) foreign import ccall unsafe "genericRaise"   c_raise :: CInt -> IO CInt #else@@ -308,9 +301,8 @@   c_raise :: CInt -> IO CInt #endif -#ifdef __GLASGOW_HASKELL__-type Signal = CInt +type Signal = CInt  -- | The actions to perform when a signal is received. data Handler = Default@@ -318,13 +310,13 @@              -- not yet: | Hold              | Catch (IO ())              | CatchOnce (IO ())-             | CatchInfo (SignalInfo -> IO ())     -- ^ /Since: 2.7.0.0/-             | CatchInfoOnce (SignalInfo -> IO ()) -- ^ /Since: 2.7.0.0/+             | CatchInfo (SignalInfo -> IO ())     -- ^ @since 2.7.0.0+             | CatchInfoOnce (SignalInfo -> IO ()) -- ^ @since 2.7.0.0   deriving (Typeable)  -- | Information about a received signal (derived from @siginfo_t@). ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 data SignalInfo = SignalInfo {       siginfoSignal   :: Signal,       siginfoError    :: Errno,@@ -334,7 +326,7 @@ -- | Information specific to a particular type of signal -- (derived from @siginfo_t@). ----- /Since: 2.7.0.0/+-- @since 2.7.0.0 data SignalSpecificInfo   = NoSignalSpecificInfo   | SigChldInfo {@@ -450,7 +442,6 @@         siginfoSpecific = extra }  #endif /* !__PARALLEL_HASKELL__ */-#endif /* __GLASGOW_HASKELL__ */  -- ----------------------------------------------------------------------------- -- Alarms@@ -465,7 +456,6 @@ foreign import ccall unsafe "alarm"   c_alarm :: CUInt -> IO CUInt -#ifdef __GLASGOW_HASKELL__ -- ----------------------------------------------------------------------------- -- The NOCLDSTOP flag @@ -484,7 +474,6 @@ queryStoppedChildFlag = do     rc <- peek nocldstop     return (rc == (0::Int))-#endif /* __GLASGOW_HASKELL__ */  -- ----------------------------------------------------------------------------- -- Manipulating signal sets@@ -575,8 +564,6 @@    throwErrnoIfMinus1_ "getPendingSignals" (c_sigpending p)   return (SignalSet fp) -#ifndef cygwin32_HOST_OS- -- | @awaitSignal iset@ suspends execution until an interrupt is received. -- If @iset@ is @Just s@, @awaitSignal@ calls @sigsuspend@, installing -- @s@ as the new signal mask before suspending execution; otherwise, it@@ -605,18 +592,8 @@  foreign import ccall unsafe "sigsuspend"   c_sigsuspend :: Ptr CSigset -> IO CInt-#endif -#ifdef __HUGS__-foreign import ccall unsafe "sigdelset"-  c_sigdelset   :: Ptr CSigset -> CInt -> IO CInt--foreign import ccall unsafe "sigfillset"-  c_sigfillset  :: Ptr CSigset -> IO CInt--foreign import ccall unsafe "sigismember"-  c_sigismember :: Ptr CSigset -> CInt -> IO CInt-#elif defined(darwin_HOST_OS) && __GLASGOW_HASKELL__ < 706+#if defined(darwin_HOST_OS) && __GLASGOW_HASKELL__ < 706 -- see http://ghc.haskell.org/trac/ghc/ticket/7359#comment:3 -- To be removed when support for GHC 7.4.x is dropped foreign import ccall unsafe "__hscore_sigdelset"@@ -636,7 +613,7 @@  foreign import capi unsafe "signal.h sigismember"   c_sigismember :: Ptr CSigset -> CInt -> IO CInt-#endif /* __HUGS__ */+#endif  foreign import ccall unsafe "sigpending"   c_sigpending :: Ptr CSigset -> IO CInt
System/Posix/Signals/Exts.hsc view
@@ -1,7 +1,5 @@ {-# LANGUAGE CPP #-}-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Safe #-}-#endif  ----------------------------------------------------------------------------- -- |
System/Posix/Temp.hsc view
@@ -1,6 +1,7 @@+{-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -33,10 +34,8 @@ import System.Posix.Types import System.Posix.Internals (withFilePath, peekFilePath) -#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)-foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"+foreign import capi unsafe "HsUnix.h mkstemp"   c_mkstemp :: CString -> IO CInt-#endif  -- | Make a unique filename and open it for reading\/writing. The returned -- 'FilePath' is the (possibly relative) path of the created file, which is@@ -48,20 +47,14 @@ mkstemp :: String -> IO (FilePath, Handle) mkstemp template' = do   let template = template' ++ "XXXXXX"-#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)   withFilePath template $ \ ptr -> do     fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)     name <- peekFilePath ptr     h <- fdToHandle (Fd fd)     return (name, h)-#else-  name <- mktemp template-  h <- openFile name ReadWriteMode-  return (name, h)-#endif  #if HAVE_MKSTEMPS-foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"+foreign import capi unsafe "HsUnix.h mkstemps"   c_mkstemps :: CString -> CInt -> IO CInt #endif @@ -85,11 +78,11 @@     h <- fdToHandle (Fd fd)     return (name, h) #else-mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform" +mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform" #endif  #if HAVE_MKDTEMP-foreign import ccall unsafe "HsUnix.h __hscore_mkdtemp"+foreign import capi unsafe "HsUnix.h mkdtemp"   c_mkdtemp :: CString -> IO CString #endif @@ -114,7 +107,7 @@   return name #endif -#if (!defined(__GLASGOW_HASKELL__) && !defined(__HUGS__)) || !HAVE_MKDTEMP+#if !HAVE_MKDTEMP  foreign import ccall unsafe "mktemp"   c_mktemp :: CString -> IO CString
System/Posix/Temp/ByteString.hsc view
@@ -1,6 +1,7 @@+{-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -38,10 +39,8 @@ import System.Posix.IO import System.Posix.Types -#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)-foreign import ccall unsafe "HsUnix.h __hscore_mkstemp"+foreign import capi unsafe "HsUnix.h mkstemp"   c_mkstemp :: CString -> IO CInt-#endif  -- | Make a unique filename and open it for reading\/writing. The returned -- 'RawFilePath' is the (possibly relative) path of the created file, which is@@ -53,24 +52,18 @@ mkstemp :: ByteString -> IO (RawFilePath, Handle) mkstemp template' = do   let template = template' `B.append` (BC.pack "XXXXXX")-#if defined(__GLASGOW_HASKELL__) || defined(__HUGS__)   withFilePath template $ \ ptr -> do     fd <- throwErrnoIfMinus1 "mkstemp" (c_mkstemp ptr)     name <- peekFilePath ptr     h <- fdToHandle (Fd fd)     return (name, h)-#else-  name <- mktemp template-  h <- openFile (BC.unpack name) ReadWriteMode-  return (name, h)-#endif  #if HAVE_MKSTEMPS-foreign import ccall unsafe "HsUnix.h __hscore_mkstemps"+foreign import capi unsafe "HsUnix.h mkstemps"   c_mkstemps :: CString -> CInt -> IO CInt #endif --- |'mkstemps' - make a unique filename with a given prefix and suffix +-- |'mkstemps' - make a unique filename with a given prefix and suffix -- and open it for reading\/writing (only safe on GHC & Hugs). -- The returned 'RawFilePath' is the (possibly relative) path of -- the created file, which contains  6 random characters in between@@ -86,11 +79,11 @@     h <- fdToHandle (Fd fd)     return (name, h) #else-mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform" +mkstemps = error "System.Posix.Temp.mkstemps: not available on this platform" #endif  #if HAVE_MKDTEMP-foreign import ccall unsafe "HsUnix.h __hscore_mkdtemp"+foreign import capi unsafe "HsUnix.h mkdtemp"   c_mkdtemp :: CString -> IO CString #endif @@ -114,7 +107,7 @@   return name #endif -#if (!defined(__GLASGOW_HASKELL__) && !defined(__HUGS__)) || !HAVE_MKDTEMP+#if !HAVE_MKDTEMP  foreign import ccall unsafe "mktemp"   c_mktemp :: CString -> IO CString
System/Posix/Terminal.hsc view
@@ -1,6 +1,7 @@+{-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -83,6 +84,11 @@  import System.Posix.Internals (peekFilePath) +#if !HAVE_CTERMID+import System.IO.Error ( ioeSetLocation )+import GHC.IO.Exception ( unsupportedOperation )+#endif+ -- | @getTerminalName fd@ calls @ttyname@ to obtain a name associated --   with the terminal for @Fd@ @fd@. If @fd@ is associated --   with a terminal, @getTerminalName@ returns the name of the@@ -100,13 +106,23 @@ --   controlling terminal exists, --   @getControllingTerminalName@ returns the name of the --   controlling terminal.+--+-- Throws 'IOError' (\"unsupported operation\") if platform does not+-- provide @ctermid(3)@ (use @#if HAVE_CTERMID@ CPP guard to+-- detect availability). getControllingTerminalName :: IO FilePath+#if HAVE_CTERMID getControllingTerminalName = do   s <- throwErrnoIfNull "getControllingTerminalName" (c_ctermid nullPtr)   peekFilePath s -foreign import ccall unsafe "ctermid"+foreign import capi unsafe "termios.h ctermid"   c_ctermid :: CString -> IO CString+#else+{-# WARNING getControllingTerminalName+    "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_CTERMID@)" #-}+getControllingTerminalName = ioError (ioeSetLocation unsupportedOperation "getControllingTerminalName")+#endif  -- | @getSlaveTerminalName@ calls @ptsname@ to obtain the name of the -- slave terminal associated with a pseudoterminal pair.  The file@@ -118,8 +134,14 @@   s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)   peekFilePath s +# if __GLASGOW_HASKELL__ < 800+-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_ptsname"   c_ptsname :: CInt -> IO CString+# else+foreign import capi unsafe "HsUnix.h ptsname"+  c_ptsname :: CInt -> IO CString+# endif #else getSlaveTerminalName _ =     ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing)@@ -172,11 +194,20 @@   c_push_module :: CInt -> CString -> IO CInt  #ifdef HAVE_PTSNAME+# if __GLASGOW_HASKELL__ < 800+-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_grantpt"   c_grantpt :: CInt -> IO CInt  foreign import ccall unsafe "__hsunix_unlockpt"   c_unlockpt :: CInt -> IO CInt+# else+foreign import capi unsafe "HsUnix.h grantpt"+  c_grantpt :: CInt -> IO CInt++foreign import capi unsafe "HsUnix.h unlockpt"+  c_unlockpt :: CInt -> IO CInt+# endif #else c_grantpt :: CInt -> IO CInt c_grantpt _ = return (fromIntegral 0)
System/Posix/Terminal/ByteString.hsc view
@@ -1,6 +1,7 @@+{-# LANGUAGE CApiFFI #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -91,6 +92,10 @@  import System.Posix.ByteString.FilePath +#if !HAVE_CTERMID+import System.IO.Error ( ioeSetLocation )+import GHC.IO.Exception ( unsupportedOperation )+#endif  -- | @getTerminalName fd@ calls @ttyname@ to obtain a name associated --   with the terminal for @Fd@ @fd@. If @fd@ is associated@@ -109,13 +114,23 @@ --   controlling terminal exists, --   @getControllingTerminalName@ returns the name of the --   controlling terminal.+--+-- Throws 'IOError' (\"unsupported operation\") if platform does not+-- provide @ctermid(3)@ (use @#if HAVE_CTERMID@ CPP guard to+-- detect availability). getControllingTerminalName :: IO RawFilePath+#if HAVE_CTERMID getControllingTerminalName = do   s <- throwErrnoIfNull "getControllingTerminalName" (c_ctermid nullPtr)   peekFilePath s -foreign import ccall unsafe "ctermid"+foreign import capi unsafe "termios.h ctermid"   c_ctermid :: CString -> IO CString+#else+{-# WARNING getControllingTerminalName+    "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_CTERMID@)" #-}+getControllingTerminalName = ioError (ioeSetLocation unsupportedOperation "getControllingTerminalName")+#endif  -- | @getSlaveTerminalName@ calls @ptsname@ to obtain the name of the -- slave terminal associated with a pseudoterminal pair.  The file@@ -127,8 +142,14 @@   s <- throwErrnoIfNull "getSlaveTerminalName" (c_ptsname fd)   peekFilePath s +# if __GLASGOW_HASKELL__ < 800+-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_ptsname"   c_ptsname :: CInt -> IO CString+# else+foreign import capi unsafe "HsUnix.h ptsname"+  c_ptsname :: CInt -> IO CString+# endif #else getSlaveTerminalName _ =     ioError (errnoToIOError "getSlaveTerminalName" eNOSYS Nothing Nothing)@@ -180,12 +201,21 @@ foreign import ccall unsafe "__hsunix_push_module"   c_push_module :: CInt -> CString -> IO CInt -#ifdef HAVE_PTSNAME+#if HAVE_PTSNAME+# if __GLASGOW_HASKELL__ < 800+-- see comment in cbits/HsUnix.c foreign import ccall unsafe "__hsunix_grantpt"   c_grantpt :: CInt -> IO CInt  foreign import ccall unsafe "__hsunix_unlockpt"   c_unlockpt :: CInt -> IO CInt+# else+foreign import capi unsafe "HsUnix.h grantpt"+  c_grantpt :: CInt -> IO CInt++foreign import capi unsafe "HsUnix.h unlockpt"+  c_unlockpt :: CInt -> IO CInt+# endif #else c_grantpt :: CInt -> IO CInt c_grantpt _ = return (fromIntegral (0::Int))
System/Posix/Terminal/Common.hsc view
@@ -1,7 +1,6 @@ {-# LANGUAGE CApiFFI #-}-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Trustworthy #-}-#endif+ ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.Terminal.Common@@ -77,11 +76,16 @@ import Foreign.Storable ( Storable(..) ) import System.IO.Unsafe ( unsafePerformIO ) import System.Posix.Types+import System.Posix.Internals ( CTermios ) +#if !HAVE_TCDRAIN+import System.IO.Error ( ioeSetLocation )+import GHC.IO.Exception ( unsupportedOperation )+#endif+ -- ----------------------------------------------------------------------------- -- Terminal attributes -type CTermios = () newtype TerminalAttributes = TerminalAttributes (ForeignPtr CTermios)  makeTerminalAttributes :: ForeignPtr CTermios -> TerminalAttributes@@ -408,12 +412,21 @@  -- | @drainOutput fd@ calls @tcdrain@ to block until all output --   written to @Fd@ @fd@ has been transmitted.+--+-- Throws 'IOError' (\"unsupported operation\") if platform does not+-- provide @tcdrain(3)@ (use @#if HAVE_TCDRAIN@ CPP guard to+-- detect availability). drainOutput :: Fd -> IO ()+#if HAVE_TCDRAIN drainOutput (Fd fd) = throwErrnoIfMinus1_ "drainOutput" (c_tcdrain fd) -foreign import capi unsafe "termios.h tcdrain"+foreign import capi safe "termios.h tcdrain"   c_tcdrain :: CInt -> IO CInt-+#else+{-# WARNING drainOutput+    "operation will throw 'IOError' \"unsupported operation\" (CPP guard: @#if HAVE_TCDRAIN@)" #-}+drainOutput _ = ioError (ioeSetLocation unsupportedOperation "drainOutput")+#endif  data QueueSelector   = InputQueue          -- TCIFLUSH@@ -527,8 +540,16 @@ baud2Word B9600 = (#const B9600) baud2Word B19200 = (#const B19200) baud2Word B38400 = (#const B38400)+#ifdef B57600 baud2Word B57600 = (#const B57600)+#else+baud2Word B57600 = error "B57600 not available on this system"+#endif+#ifdef B115200 baud2Word B115200 = (#const B115200)+#else+baud2Word B115200 = error "B115200 not available on this system"+#endif  -- And convert a word back to a baud rate -- We really need some cpp macros here.@@ -551,8 +572,12 @@     else if x == (#const B9600) then B9600     else if x == (#const B19200) then B19200     else if x == (#const B38400) then B38400+#ifdef B57600     else if x == (#const B57600) then B57600+#endif+#ifdef B115200     else if x == (#const B115200) then B115200+#endif     else error "unknown baud rate"  -- Clear termios i_flag
+ System/Posix/Time.hs view
@@ -0,0 +1,41 @@+{-# LANGUAGE CApiFFI #-}+{-# LANGUAGE CPP #-}+#if __GLASGOW_HASKELL__ >= 709+{-# LANGUAGE Safe #-}+#else+{-# LANGUAGE Trustworthy #-}+#endif+-----------------------------------------------------------------------------+-- |+-- Module      :  System.Posix.Time+-- Copyright   :  (c) The University of Glasgow 2002+-- License     :  BSD-style (see the file libraries/base/LICENSE)+--+-- Maintainer  :  libraries@haskell.org+-- Stability   :  provisional+-- Portability :  non-portable (requires POSIX)+--+-- POSIX Time support+--+-----------------------------------------------------------------------------++module System.Posix.Time (+        epochTime,+        -- ToDo: lots more from sys/time.h+        -- how much already supported by System.Time?+  ) where++import System.Posix.Types+import Foreign+import Foreign.C++-- -----------------------------------------------------------------------------+-- epochTime++-- | @epochTime@ calls @time@ to obtain the number of+--   seconds that have elapsed since the epoch (Jan 01 00:00:00 GMT 1970).+epochTime :: IO EpochTime+epochTime = throwErrnoIfMinus1 "epochTime" (c_time nullPtr)++foreign import capi unsafe "HsUnix.h time"+  c_time :: Ptr CTime -> IO CTime
− System/Posix/Time.hsc
@@ -1,41 +0,0 @@-#if __GLASGOW_HASKELL__ >= 709-{-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703-{-# LANGUAGE Trustworthy #-}-#endif--------------------------------------------------------------------------------- |--- Module      :  System.Posix.Time--- Copyright   :  (c) The University of Glasgow 2002--- License     :  BSD-style (see the file libraries/base/LICENSE)------ Maintainer  :  libraries@haskell.org--- Stability   :  provisional--- Portability :  non-portable (requires POSIX)------ POSIX Time support-----------------------------------------------------------------------------------module System.Posix.Time (-        epochTime,-        -- ToDo: lots more from sys/time.h-        -- how much already supported by System.Time?-  ) where--#include "HsUnix.h"--import System.Posix.Types-import Foreign-import Foreign.C---- -------------------------------------------------------------------------------- epochTime---- | @epochTime@ calls @time@ to obtain the number of---   seconds that have elapsed since the epoch (Jan 01 00:00:00 GMT 1970).-epochTime :: IO EpochTime-epochTime = throwErrnoIfMinus1 "epochTime" (c_time nullPtr)--foreign import ccall unsafe "__hsunix_time"-  c_time :: Ptr CTime -> IO CTime
System/Posix/Unistd.hsc view
@@ -2,7 +2,7 @@ {-# LANGUAGE NondecreasingIndentation #-} #if __GLASGOW_HASKELL__ >= 709 {-# LANGUAGE Safe #-}-#elif __GLASGOW_HASKELL__ >= 703+#else {-# LANGUAGE Trustworthy #-} #endif -----------------------------------------------------------------------------@@ -118,9 +118,7 @@ sleep 0 = return 0 sleep secs = do r <- c_sleep (fromIntegral secs); return (fromIntegral r) -#ifdef __GLASGOW_HASKELL__ {-# WARNING sleep "This function has several shortcomings (see documentation). Please consider using Control.Concurrent.threadDelay instead." #-}-#endif  foreign import ccall safe "sleep"   c_sleep :: CUInt -> IO CUInt@@ -181,9 +179,9 @@                        else throwErrno "nanosleep"      loop (fromIntegral tv_sec0 :: CTime) (fromIntegral tv_nsec0 :: CTime) -data CTimeSpec+data {-# CTYPE "struct timespec" #-} CTimeSpec -foreign import ccall safe "__hsunix_nanosleep"+foreign import capi safe "HsUnix.h nanosleep"   c_nanosleep :: Ptr CTimeSpec -> Ptr CTimeSpec -> IO CInt #endif @@ -229,7 +227,7 @@ -- provide @fsync(2)@ (use @#if HAVE_FSYNC@ CPP guard to -- detect availability). ----- /Since: 2.7.1.0/+-- @since 2.7.1.0 fileSynchronise :: Fd -> IO () #if HAVE_FSYNC fileSynchronise fd = do@@ -250,7 +248,7 @@ -- provide @fdatasync(2)@ (use @#if HAVE_FDATASYNC@ CPP guard to -- detect availability). ----- /Since: 2.7.1.0/+-- @since 2.7.1.0 fileSynchroniseDataOnly :: Fd -> IO () #if HAVE_FDATASYNC fileSynchroniseDataOnly fd = do
System/Posix/User.hsc view
@@ -1,6 +1,4 @@-#ifdef __GLASGOW_HASKELL__ {-# LANGUAGE Trustworthy, CApiFFI #-}-#endif ----------------------------------------------------------------------------- -- | -- Module      :  System.Posix.User@@ -55,7 +53,6 @@ import Foreign.Ptr import Foreign.Marshal import Foreign.Storable-import System.Posix.Internals   ( CGroup, CPasswd )  #if !defined(HAVE_GETPWNAM_R) || !defined(HAVE_GETPWUID_R) || defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT) import Control.Concurrent.MVar  ( MVar, newMVar, withMVar )@@ -66,6 +63,10 @@ import Control.Monad import System.IO.Error +-- internal types+data {-# CTYPE "struct passwd" #-} CPasswd+data {-# CTYPE "struct group"  #-} CGroup+ -- ----------------------------------------------------------------------------- -- user environemnt @@ -320,7 +321,7 @@     doubleAllocWhileERANGE "getUserEntryForID" "user" pwBufSize unpackUserEntry $       c_getpwuid_r uid ppw -foreign import ccall unsafe "__hsunix_getpwuid_r"+foreign import capi unsafe "HsUnix.h getpwuid_r"   c_getpwuid_r :: CUid -> Ptr CPasswd ->                         CString -> CSize -> Ptr (Ptr CPasswd) -> IO CInt #elif HAVE_GETPWUID@@ -347,7 +348,7 @@       doubleAllocWhileERANGE "getUserEntryForName" "user" pwBufSize unpackUserEntry $         c_getpwnam_r pstr ppw -foreign import ccall unsafe "__hsunix_getpwnam_r"+foreign import capi unsafe "HsUnix.h getpwnam_r"   c_getpwnam_r :: CString -> Ptr CPasswd                -> CString -> CSize -> Ptr (Ptr CPasswd) -> IO CInt #elif HAVE_GETPWNAM@@ -378,11 +379,11 @@                      else do thisentry <- unpackUserEntry ppw                              worker (thisentry : accum) -foreign import ccall unsafe "__hsunix_getpwent"+foreign import capi unsafe "HsUnix.h getpwent"   c_getpwent :: IO (Ptr CPasswd)-foreign import ccall unsafe "setpwent"+foreign import capi unsafe "HsUnix.h setpwent"   c_setpwent :: IO ()-foreign import ccall unsafe "endpwent"+foreign import capi unsafe "HsUnix.h endpwent"   c_endpwent :: IO () #else getAllUserEntries = error "System.Posix.User.getAllUserEntries: not supported"
cbits/HsUnix.c view
@@ -8,170 +8,92 @@  #include "HsUnix.h" -int __hsunix_wifexited   (int stat) { return WIFEXITED(stat); }-int __hsunix_wexitstatus (int stat) { return WEXITSTATUS(stat); }-int __hsunix_wifsignaled (int stat) { return WIFSIGNALED(stat); }-int __hsunix_wtermsig    (int stat) { return WTERMSIG(stat); }-int __hsunix_wifstopped  (int stat) { return WIFSTOPPED(stat); }-int __hsunix_wstopsig    (int stat) { return WSTOPSIG(stat); }-int __hsunix_wcoredump   (int stat) { return WCOREDUMP(stat); }- #ifdef HAVE_RTLDNEXT-void *__hsunix_rtldNext (void) {return RTLD_NEXT;} +void *__hsunix_rtldNext (void) {return RTLD_NEXT;} #endif  #ifdef HAVE_RTLDDEFAULT void *__hsunix_rtldDefault (void) {return RTLD_DEFAULT;} #endif -// lstat is a macro on some platforms, so we need a wrapper:-int __hsunix_lstat(const char *path, struct stat *buf) -{ -    return lstat(path,buf);-}--// mknod is a macro on some platforms, so we need a wrapper:-int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev)-{ -    return mknod(pathname,mode,dev);-}--#ifdef HAVE_GETPWENT-// getpwent is a macro on some platforms, so we need a wrapper:-struct passwd *__hsunix_getpwent(void)-{-    return getpwent();-}-#endif--#if HAVE_GETPWNAM_R-// getpwnam_r is a macro on some platforms, so we need a wrapper:-int __hsunix_getpwnam_r(const char *name, struct passwd *pw, char *buffer,-                        size_t buflen, struct passwd **result)-{-    return getpwnam_r(name, pw, buffer, buflen, result);-}-#endif--#ifdef HAVE_GETPWUID_R-// getpwuid_r is a macro on some platforms, so we need a wrapper:-int __hsunix_getpwuid_r(uid_t uid, struct passwd *pw, char *buffer,-                        size_t buflen, struct passwd **result)-{-    return getpwuid_r(uid, pw, buffer, buflen, result);-}-#endif--#ifdef HAVE_NANOSLEEP-// nanosleep is a macro on some platforms, so we need a wrapper:-int __hsunix_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)-{-    return nanosleep(rqtp, rmtp);-}-#endif--// opendir is a macro on some platforms, so we need a wrapper:-DIR *__hsunix_opendir(const char *filename)-{-    return opendir(filename);-}--// time is a macro on some platforms, so we need a wrapper:-time_t __hsunix_time(time_t *tloc)-{-    return time(tloc);-}--// times is a macro on some platforms, so we need a wrapper:-clock_t __hsunix_times(struct tms *tp)-{-    return times(tp);-}--#ifdef HAVE_PTSNAME-// I cannot figure out how to make the definitions of the following-// functions visible in <stdlib.h> on Linux.  But these definitions-// follow the POSIX specs, and everything links and runs.--char *__hsunix_ptsname(int fd)-{-    extern char *ptsname(int);-    return ptsname(fd);-}--int __hsunix_grantpt(int fd)-{-    extern int grantpt(int);-    return grantpt(fd);-}+#if HAVE_PTSNAME && (__GLASGOW_HASKELL__ < 800)+// On Linux (and others), <stdlib.h> needs to be included while+// `_XOPEN_SOURCE` is already defined. However, GHCs before GHC 8.0+// didn't do that yet for CApiFFI, so we need this workaround here. -int __hsunix_unlockpt(int fd)-{-    extern int unlockpt(int);-    return unlockpt(fd);-}+char *__hsunix_ptsname(int fd)   { return ptsname(fd);  }+int   __hsunix_grantpt(int fd)   { return grantpt(fd);  }+int   __hsunix_unlockpt(int fd)  { return unlockpt(fd); } #endif  // push a SVR4 STREAMS module; do nothing if STREAMS not available int __hsunix_push_module(int fd, const char *module) {-#if defined(I_PUSH) && !defined(__CYGWIN__) && !defined(HAVE_DEV_PTC)+#if defined(I_PUSH) && !defined(HAVE_DEV_PTC)     return ioctl(fd, I_PUSH, module); #else     return 0; #endif } -#if !defined(__MINGW32__)-int __hscore_mkstemp(char *filetemplate) {-    return (mkstemp(filetemplate));-}-#endif--#if HAVE_MKSTEMPS-int __hscore_mkstemps(char *filetemplate, int suffixlen) {-    return (mkstemps(filetemplate, suffixlen));-}-#endif+/*+ * read an entry from the directory stream; opt for the+ * re-entrant friendly way of doing this, if available.+ */+int __hscore_readdir( DIR *dirPtr, struct dirent **pDirEnt )+{+#if HAVE_READDIR_R+  struct dirent* p;+  int res;+  static unsigned int nm_max = (unsigned int)-1; -#if HAVE_MKDTEMP-char *__hscore_mkdtemp(char *filetemplate) {-    return (mkdtemp(filetemplate));-}+  if (pDirEnt == NULL) {+    return -1;+  }+  if (nm_max == (unsigned int)-1) {+#ifdef NAME_MAX+    nm_max = NAME_MAX + 1;+#else+    nm_max = pathconf(".", _PC_NAME_MAX);+    if (nm_max == -1) { nm_max = 255; }+    nm_max++; #endif-+  }+  p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);+  if (p == NULL) return -1;+  res = readdir_r(dirPtr, p, pDirEnt);+  if (res != 0) {+      *pDirEnt = NULL;+      free(p);+  }+  else if (*pDirEnt == NULL) {+    // end of stream+    free(p);+  }+  return res;+#else -#if !defined(__MINGW32__) && !defined(irix_HOST_OS)-int __hscore_getrlimit(int resource, struct rlimit *rlim) {-    return (getrlimit(resource, rlim));-}+  if (pDirEnt == NULL) {+    return -1;+  } -int __hscore_setrlimit(int resource, struct rlimit *rlim) {-    return (setrlimit(resource, rlim));-}+  *pDirEnt = readdir(dirPtr);+  if (*pDirEnt == NULL) {+    return -1;+  } else {+    return 0;+  } #endif+} -#ifdef HAVE_UNSETENV-int __hsunix_unsetenv(const char *name)+char *__hscore_d_name( struct dirent* d ) {-#ifdef UNSETENV_RETURNS_VOID-    unsetenv(name);-    return 0;-#else-    return unsetenv(name);-#endif+  return (d->d_name); }-#endif -/* A size that will contain many path names, but not necessarily all- * (PATH_MAX is not defined on systems with unlimited path length,- * e.g. the Hurd).- */-HsInt __hsunix_long_path_size(void) {-#ifdef PATH_MAX-    return PATH_MAX;-#else-    return 4096;+void __hscore_free_dirent(struct dirent *dEnt)+{+#if HAVE_READDIR_R+  free(dEnt); #endif }-
− cbits/dirUtils.c
@@ -1,83 +0,0 @@-/* - * (c) The University of Glasgow 2002- *- * Directory Runtime Support- */--/* needed only for solaris2_HOST_OS */-#ifdef __GLASGOW_HASKELL__-#include "ghcconfig.h"-#endif--// The following is required on Solaris to force the POSIX versions of-// the various _r functions instead of the Solaris versions.-#ifdef solaris2_HOST_OS-#define _POSIX_PTHREAD_SEMANTICS-#endif--#include "HsUnix.h"--/*- * read an entry from the directory stream; opt for the- * re-entrant friendly way of doing this, if available.- */-int-__hscore_readdir( DIR *dirPtr, struct dirent **pDirEnt )-{-#if HAVE_READDIR_R-  struct dirent* p;-  int res;-  static unsigned int nm_max = (unsigned int)-1;-  -  if (pDirEnt == NULL) {-    return -1;-  }-  if (nm_max == (unsigned int)-1) {-#ifdef NAME_MAX-    nm_max = NAME_MAX + 1;-#else-    nm_max = pathconf(".", _PC_NAME_MAX);-    if (nm_max == -1) { nm_max = 255; }-    nm_max++;-#endif-  }-  p = (struct dirent*)malloc(sizeof(struct dirent) + nm_max);-  if (p == NULL) return -1;-  res = readdir_r(dirPtr, p, pDirEnt);-  if (res != 0) {-      *pDirEnt = NULL;-      free(p);-  }-  else if (*pDirEnt == NULL) {-    // end of stream-    free(p);-  }-  return res;-#else--  if (pDirEnt == NULL) {-    return -1;-  }--  *pDirEnt = readdir(dirPtr);-  if (*pDirEnt == NULL) {-    return -1;-  } else {-    return 0;-  }  -#endif-}--char *-__hscore_d_name( struct dirent* d )-{-  return (d->d_name);-}--void-__hscore_free_dirent(struct dirent *dEnt)-{-#if HAVE_READDIR_R-  free(dEnt);-#endif-}
cbits/execvpe.c view
@@ -11,10 +11,6 @@  #include "HsUnixConfig.h" -#if HAVE_EXECVPE-# define _GNU_SOURCE-#endif- #include <errno.h> #include <sys/types.h> #if HAVE_SYS_WAIT_H@@ -28,6 +24,11 @@  #define HSUNIX_EXECVPE_H_NO_COMPAT #include "execvpe.h"++#if !defined(execvpe) && !HAVE_DECL_EXECVPE+// On some archs such as AIX, the prototype may be missing+int execvpe(const char *file, char *const argv[], char *const envp[]);+#endif  /*  * We want the search semantics of execvp, but we want to provide our
− cbits/ghcrts.c
@@ -1,15 +0,0 @@-#ifdef __GLASGOW_HASKELL__-// for 'void StopTimer(void)' prototype-# include "Rts.h"-#endif--#define HSUNIX_EXECVPE_H_NO_COMPAT-#include "execvpe.h"--/* Copied verbatim from ghc/lib/std/cbits/system.c. */-void pPrPr_disableITimers (void)-{-#ifdef __GLASGOW_HASKELL__-    stopTimer();-#endif-}
changelog.md view
@@ -1,5 +1,26 @@ # Changelog for [`unix` package](http://hackage.haskell.org/package/unix) +## 2.7.2.0  *Apr 2016*++  * Bundled with GHC 8.0.1++  * Don't assume non-POSIX `WCOREDUMP(x)` macro exists++  * Don't assume existence of `termios(3)` constants beyond `B38400`++  * Don't assume existence of `ctermid(3)`/`tcdrain(3)`++  * Change `drainOutput`'s `tcdrain(3)` into a `safe` FFI call++  * Turn build error into compile warnings for exotic `struct stat`+    configurations (GHC #8859)++  * Improve detection of `fdatasync(2)` (GHC #11137)++  * Drop support for Hugs++  * Drop support for Cygwin (and Windows in general)+ ## 2.7.1.0  *Dec 2014*    * Bundled with GHC 7.10.1
configure view
@@ -689,7 +689,6 @@ ac_subst_files='' ac_user_opts=' enable_option_checking-with_cc enable_largefile '       ac_precious_vars='build_alias@@ -1317,11 +1316,6 @@   --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]   --disable-largefile     omit support for large files -Optional Packages:-  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]-  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)-C compiler- Some influential environment variables:   CC          C compiler command   CFLAGS      C compiler flags@@ -1764,6 +1758,52 @@  } # ac_fn_c_check_func +# ac_fn_c_check_decl LINENO SYMBOL VAR INCLUDES+# ---------------------------------------------+# Tests whether SYMBOL is declared in INCLUDES, setting cache variable VAR+# accordingly.+ac_fn_c_check_decl ()+{+  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack+  as_decl_name=`echo $2|sed 's/ *(.*//'`+  as_decl_use=`echo $2|sed -e 's/(/((/' -e 's/)/) 0&/' -e 's/,/) 0& (/g'`+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $as_decl_name is declared" >&5+$as_echo_n "checking whether $as_decl_name is declared... " >&6; }+if eval \${$3+:} false; then :+  $as_echo_n "(cached) " >&6+else+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext+/* end confdefs.h.  */+$4+int+main ()+{+#ifndef $as_decl_name+#ifdef __cplusplus+  (void) $as_decl_use;+#else+  (void) $as_decl_name;+#endif+#endif++  ;+  return 0;+}+_ACEOF+if ac_fn_c_try_compile "$LINENO"; then :+  eval "$3=yes"+else+  eval "$3=no"+fi+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext+fi+eval ac_res=\$$3+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5+$as_echo "$ac_res" >&6; }+  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno++} # ac_fn_c_check_decl+ # ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES # ---------------------------------------------------- # Tries to find if the field MEMBER exists in type AGGR, after including@@ -2359,12 +2399,6 @@ # Safety check: Ensure that we are in the correct source directory.  --# Check whether --with-cc was given.-if test "${with_cc+set}" = set; then :-  withval=$with_cc; CC=$withval-fi- ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'@@ -3155,11 +3189,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu  -ac_config_headers="$ac_config_headers include/HsUnixConfig.h" --# Is this a Unix system?- ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'@@ -3557,6 +3587,72 @@ done  ++  ac_fn_c_check_header_mongrel "$LINENO" "minix/config.h" "ac_cv_header_minix_config_h" "$ac_includes_default"+if test "x$ac_cv_header_minix_config_h" = xyes; then :+  MINIX=yes+else+  MINIX=+fi+++  if test "$MINIX" = yes; then++$as_echo "#define _POSIX_SOURCE 1" >>confdefs.h+++$as_echo "#define _POSIX_1_SOURCE 2" >>confdefs.h+++$as_echo "#define _MINIX 1" >>confdefs.h++  fi+++  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether it is safe to define __EXTENSIONS__" >&5+$as_echo_n "checking whether it is safe to define __EXTENSIONS__... " >&6; }+if ${ac_cv_safe_to_define___extensions__+:} false; then :+  $as_echo_n "(cached) " >&6+else+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext+/* end confdefs.h.  */++#         define __EXTENSIONS__ 1+          $ac_includes_default+int+main ()+{++  ;+  return 0;+}+_ACEOF+if ac_fn_c_try_compile "$LINENO"; then :+  ac_cv_safe_to_define___extensions__=yes+else+  ac_cv_safe_to_define___extensions__=no+fi+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext+fi+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_safe_to_define___extensions__" >&5+$as_echo "$ac_cv_safe_to_define___extensions__" >&6; }+  test $ac_cv_safe_to_define___extensions__ = yes &&+    $as_echo "#define __EXTENSIONS__ 1" >>confdefs.h++  $as_echo "#define _ALL_SOURCE 1" >>confdefs.h++  $as_echo "#define _GNU_SOURCE 1" >>confdefs.h++  $as_echo "#define _POSIX_PTHREAD_SEMANTICS 1" >>confdefs.h++  $as_echo "#define _TANDEM_SOURCE 1" >>confdefs.h++++ac_config_headers="$ac_config_headers include/HsUnixConfig.h"+++# Is this a Unix system? ac_fn_c_check_header_mongrel "$LINENO" "dlfcn.h" "ac_cv_header_dlfcn_h" "$ac_includes_default" if test "x$ac_cv_header_dlfcn_h" = xyes; then :   BUILD_PACKAGE_BOOL=True@@ -4009,6 +4105,29 @@ done  +for ac_func in _NSGetEnviron+do :+  ac_fn_c_check_func "$LINENO" "_NSGetEnviron" "ac_cv_func__NSGetEnviron"+if test "x$ac_cv_func__NSGetEnviron" = xyes; then :+  cat >>confdefs.h <<_ACEOF+#define HAVE__NSGETENVIRON 1+_ACEOF++fi+done+++ac_fn_c_check_decl "$LINENO" "execvpe" "ac_cv_have_decl_execvpe" "$ac_includes_default"+if test "x$ac_cv_have_decl_execvpe" = xyes; then :+  ac_have_decl=1+else+  ac_have_decl=0+fi++cat >>confdefs.h <<_ACEOF+#define HAVE_DECL_EXECVPE $ac_have_decl+_ACEOF+ for ac_func in execvpe do :   ac_fn_c_check_func "$LINENO" "execvpe" "ac_cv_func_execvpe"@@ -4224,18 +4343,48 @@   # Functions for file synchronization and allocation control-for ac_func in fsync fdatasync+for ac_func in fsync do :-  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`-ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"-if eval test \"x\$"$as_ac_var"\" = x"yes"; then :+  ac_fn_c_check_func "$LINENO" "fsync" "ac_cv_func_fsync"+if test "x$ac_cv_func_fsync" = xyes; then :   cat >>confdefs.h <<_ACEOF-#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1+#define HAVE_FSYNC 1 _ACEOF  fi done ++# On OSX linking against 'fdatasync' succeeds, but that doesn't pick+# the expected the POSIX 'fdatasync' function.  So make sure that we+# also have a function declaration in scope, in addition to being able+# to link against 'fdatasync'.+ac_fn_c_check_decl "$LINENO" "fdatasync" "ac_cv_have_decl_fdatasync" "$ac_includes_default"+if test "x$ac_cv_have_decl_fdatasync" = xyes; then :+  ac_have_decl=1+else+  ac_have_decl=0+fi++cat >>confdefs.h <<_ACEOF+#define HAVE_DECL_FDATASYNC $ac_have_decl+_ACEOF+if test $ac_have_decl = 1; then :+  for ac_func in fdatasync+do :+  ac_fn_c_check_func "$LINENO" "fdatasync" "ac_cv_func_fdatasync"+if test "x$ac_cv_func_fdatasync" = xyes; then :+  cat >>confdefs.h <<_ACEOF+#define HAVE_FDATASYNC 1+_ACEOF++fi+done++fi+++ for ac_func in posix_fadvise posix_fallocate do :   as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`@@ -4247,6 +4396,51 @@  fi done+++# Some termios(3) functions known to be missing sometimes (see also #55)+ac_fn_c_check_decl "$LINENO" "tcdrain" "ac_cv_have_decl_tcdrain" "$ac_includes_default+#ifdef HAVE_TERMIOS_H+#include <termios.h>+#endif++"+if test "x$ac_cv_have_decl_tcdrain" = xyes; then :+  ac_have_decl=1+else+  ac_have_decl=0+fi++cat >>confdefs.h <<_ACEOF+#define HAVE_DECL_TCDRAIN $ac_have_decl+_ACEOF+if test $ac_have_decl = 1; then :++$as_echo "#define HAVE_TCDRAIN 1" >>confdefs.h++fi+++ac_fn_c_check_decl "$LINENO" "ctermid" "ac_cv_have_decl_ctermid" "$ac_includes_default+#ifdef HAVE_TERMIOS_H+#include <termios.h>+#endif++"+if test "x$ac_cv_have_decl_ctermid" = xyes; then :+  ac_have_decl=1+else+  ac_have_decl=0+fi++cat >>confdefs.h <<_ACEOF+#define HAVE_DECL_CTERMID $ac_have_decl+_ACEOF+if test $ac_have_decl = 1; then :++$as_echo "#define HAVE_CTERMID 1" >>confdefs.h++fi   # Avoid adding rt if absent or unneeded
configure.ac view
@@ -1,13 +1,14 @@+AC_PREREQ([2.60]) AC_INIT([Haskell unix package], [2.0], [libraries@haskell.org], [unix])  # Safety check: Ensure that we are in the correct source directory. AC_CONFIG_SRCDIR([include/HsUnix.h]) -AC_ARG_WITH([cc],-            [C compiler],-            [CC=$withval])-AC_PROG_CC()+AC_PROG_CC +dnl make extensions visible to allow feature-tests to detect them lateron+AC_USE_SYSTEM_EXTENSIONS+ AC_CONFIG_HEADERS([include/HsUnixConfig.h])  # Is this a Unix system?@@ -39,7 +40,12 @@ dnl not available on android so check for it AC_CHECK_FUNCS([telldir seekdir]) +dnl When available, _NSGetEnviron() (defined in <crt_externs.h>) is+dnl the preferred way to access environ(7)+AC_CHECK_FUNCS([_NSGetEnviron])+ dnl This is e.g. available as a GNU extension in glibc 2.11++AC_CHECK_DECLS([execvpe]) AC_CHECK_FUNCS([execvpe])  AC_CHECK_MEMBERS([struct stat.st_atim])@@ -68,8 +74,29 @@ AC_CHECK_FUNCS([mkstemps mkdtemp])  # Functions for file synchronization and allocation control-AC_CHECK_FUNCS([fsync fdatasync])+AC_CHECK_FUNCS([fsync])++# On OSX linking against 'fdatasync' succeeds, but that doesn't pick+# the expected the POSIX 'fdatasync' function.  So make sure that we+# also have a function declaration in scope, in addition to being able+# to link against 'fdatasync'.+AC_CHECK_DECLS([fdatasync],[AC_CHECK_FUNCS([fdatasync])])++ AC_CHECK_FUNCS([posix_fadvise posix_fallocate])++# Some termios(3) functions known to be missing sometimes (see also #55)+AC_CHECK_DECLS([tcdrain],[AC_DEFINE([HAVE_TCDRAIN],[1],[Define to 1 if you have the `tcdrain' function.])],[],[AC_INCLUDES_DEFAULT+#ifdef HAVE_TERMIOS_H+#include <termios.h>+#endif+])++AC_CHECK_DECLS([ctermid],[AC_DEFINE([HAVE_CTERMID],[1],[Define to 1 if you have the `ctermid' function.])],[],[AC_INCLUDES_DEFAULT+#ifdef HAVE_TERMIOS_H+#include <termios.h>+#endif+])  # Avoid adding rt if absent or unneeded # shm_open needs -lrt on linux
include/HsUnix.h view
@@ -19,10 +19,6 @@ #undef PACKAGE_TARNAME #undef PACKAGE_VERSION -#ifdef solaris2_HOST_OS-#define _POSIX_PTHREAD_SEMANTICS-#endif- #include <stdlib.h> #include <stdio.h> @@ -93,18 +89,12 @@ #include <signal.h> #endif -/* in Signals.c */+/* defined in rts/posix/Signals.c */ extern HsInt nocldstop; +/* defined in libc */ extern char **environ; -int __hsunix_wifexited   (int stat);-int __hsunix_wexitstatus (int stat);-int __hsunix_wifsignaled (int stat);-int __hsunix_wtermsig    (int stat);-int __hsunix_wifstopped  (int stat);-int __hsunix_wstopsig    (int stat);- #ifdef HAVE_RTLDNEXT void *__hsunix_rtldNext (void); #endif@@ -116,82 +106,15 @@ /* O_SYNC doesn't exist on Mac OS X and (at least some versions of) FreeBSD, fall back to O_FSYNC, which should be the same */ #ifndef O_SYNC-#define O_SYNC O_FSYNC-#endif--// lstat is a macro on some platforms, so we need a wrapper:-int __hsunix_lstat(const char *path, struct stat *buf);--// lstat is a macro on some platforms, so we need a wrapper:-int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev);--#ifdef HAVE_GETPWENT-// getpwent is a macro on some platforms, so we need a wrapper:-struct passwd *__hsunix_getpwent(void);-#endif--#if HAVE_GETPWNAM_R-// getpwnam_r is a macro on some platforms, so we need a wrapper:-int __hsunix_getpwnam_r(const char *, struct passwd *, char *, size_t,-                        struct passwd **);-#endif--#ifdef HAVE_GETPWUID_R-// getpwuid_r is a macro on some platforms, so we need a wrapper:-int __hsunix_getpwuid_r(uid_t, struct passwd *, char *, size_t,-                        struct passwd **);-#endif--#ifdef HAVE_NANOSLEEP-// nanosleep is a macro on some platforms, so we need a wrapper:-int __hsunix_nanosleep(const struct timespec *, struct timespec *);+# define O_SYNC O_FSYNC #endif -// opendir is a macro on some platforms, so we need a wrapper:-DIR *__hsunix_opendir(const char *);--// time is a macro on some platforms, so we need a wrapper:-time_t __hsunix_time(time_t *);--// times is a macro on some platforms, so we need a wrapper:-clock_t __hsunix_times(struct tms *);--#ifdef HAVE_PTSNAME-// I cannot figure out how to make the definitions of the following-// functions visible in <stdlib.h> on Linux.  But these definitions-// follow the POSIX specs, and everything links and runs.--char *__hsunix_ptsname(int fd);-int __hsunix_grantpt(int fd);-int __hsunix_unlockpt(int fd);+// not part of POSIX, hence may not be always defined+#ifndef WCOREDUMP+# define WCOREDUMP(s) 0 #endif  // push a SVR4 STREAMS module; do nothing if STREAMS not available int __hsunix_push_module(int fd, const char *module);--#if !defined(__MINGW32__)-int __hscore_mkstemp(char *filetemplate);-#endif--#if HAVE_MKSTEMPS-int __hscore_mkstemps(char *filetemplate, int suffixlen);-#endif--#if HAVE_MKDTEMP-char *__hscore_mkdtemp(char *filetemplate);-#endif--#if !defined(__MINGW32__) && !defined(irix_HOST_OS)-int __hscore_getrlimit(int resource, struct rlimit *rlim);-int __hscore_setrlimit(int resource, struct rlimit *rlim);-#endif--int __hsunix_unsetenv(const char *name);--/* A size that will contain many path names, but not necessarily all- * (PATH_MAX is not defined on systems with unlimited path length,- * e.g. the Hurd).- */-HsInt __hsunix_long_path_size();  #endif
include/HsUnixConfig.h.in view
@@ -105,6 +105,25 @@ /* Define to 1 if you have the `clearenv' function. */ #undef HAVE_CLEARENV +/* Define to 1 if you have the `ctermid' function. */+#undef HAVE_CTERMID++/* Define to 1 if you have the declaration of `ctermid', and to 0 if you+   don't. */+#undef HAVE_DECL_CTERMID++/* Define to 1 if you have the declaration of `execvpe', and to 0 if you+   don't. */+#undef HAVE_DECL_EXECVPE++/* Define to 1 if you have the declaration of `fdatasync', and to 0 if you+   don't. */+#undef HAVE_DECL_FDATASYNC++/* Define to 1 if you have the declaration of `tcdrain', and to 0 if you+   don't. */+#undef HAVE_DECL_TCDRAIN+ /* Define if we have /dev/ptc. */ #undef HAVE_DEV_PTC @@ -321,6 +340,9 @@ /* Define to 1 if you have the <sys/wait.h> header file. */ #undef HAVE_SYS_WAIT_H +/* Define to 1 if you have the `tcdrain' function. */+#undef HAVE_TCDRAIN+ /* Define to 1 if you have the `telldir' function. */ #undef HAVE_TELLDIR @@ -345,6 +367,9 @@ /* Define to 1 if you have the <utmp.h> header file. */ #undef HAVE_UTMP_H +/* Define to 1 if you have the `_NSGetEnviron' function. */+#undef HAVE__NSGETENVIRON+ /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT @@ -369,6 +394,28 @@ /* Define if stdlib.h declares unsetenv to return void. */ #undef UNSETENV_RETURNS_VOID +/* Enable extensions on AIX 3, Interix.  */+#ifndef _ALL_SOURCE+# undef _ALL_SOURCE+#endif+/* Enable GNU extensions on systems that have them.  */+#ifndef _GNU_SOURCE+# undef _GNU_SOURCE+#endif+/* Enable threading extensions on Solaris.  */+#ifndef _POSIX_PTHREAD_SEMANTICS+# undef _POSIX_PTHREAD_SEMANTICS+#endif+/* Enable extensions on HP NonStop.  */+#ifndef _TANDEM_SOURCE+# undef _TANDEM_SOURCE+#endif+/* Enable general extensions on Solaris.  */+#ifndef __EXTENSIONS__+# undef __EXTENSIONS__+#endif++ /* Define if the system headers declare usleep to return void. */ #undef USLEEP_RETURNS_VOID @@ -382,6 +429,16 @@  /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES++/* Define to 1 if on MINIX. */+#undef _MINIX++/* Define to 2 if the system does not provide POSIX.1 features except with+   this defined. */+#undef _POSIX_1_SOURCE++/* Define to 1 if you need to in order for `stat' and other things to work. */+#undef _POSIX_SOURCE  /* Define to empty if `const' does not conform to ANSI C. */ #undef const
include/execvpe.h view
@@ -14,7 +14,6 @@ #ifndef HSUNIX_EXECVPE_H_NO_COMPAT #include "HsUnixConfig.h" #if HAVE_EXECVPE-# define _GNU_SOURCE # include <unistd.h> extern int execvpe(const char *name, char *const argv[], char *const envp[]);@@ -22,8 +21,5 @@ # define execvpe(name,argv,envp) __hsunix_execvpe(name,argv,envp) #endif #endif--// implemented in cbits/ghcrts.c-extern void pPrPr_disableITimers (void);  #endif
unix.cabal view
@@ -1,5 +1,5 @@ name:           unix-version:        2.7.1.0+version:        2.7.2.0 -- NOTE: Don't forget to update ./changelog.md license:        BSD3 license-file:   LICENSE@@ -13,11 +13,12 @@ tested-with:    GHC>=7.4.1 description:     This package gives you access to the set of operating system-    services standardised by POSIX 1003.1b (or the IEEE Portable-    Operating System Interface for Computing Environments --    IEEE Std. 1003.1).+    services standardised by+    <http://pubs.opengroup.org/onlinepubs/9699919799/ POSIX.1-2008>+    (or the IEEE Portable Operating System Interface for Computing+    Environments - IEEE Std. 1003.1).     .-    The package is not supported under Windows (except under Cygwin).+    The package is not supported under Windows.  extra-source-files:     changelog.md@@ -49,19 +50,21 @@         DeriveDataTypeable         InterruptibleFFI         NondecreasingIndentation-        OverloadedStrings         RankNTypes         RecordWildCards+        Safe+        Trustworthy -    if impl(ghc)-        other-extensions:-            Safe-            Trustworthy+    if os(windows)+        -- This package currently supports neither Cygwin nor MinGW,+        -- therefore os(windows) is effectively not supported.+        build-depends: unbuildable<0+        buildable: False      build-depends:-        base        >= 4.5     && < 4.9,+        base        >= 4.5     && < 4.10,         bytestring  >= 0.9.2   && < 0.11,-        time        >= 1.2     && < 1.6+        time        >= 1.2     && < 1.7      exposed-modules:         System.Posix@@ -128,6 +131,4 @@         execvpe.h     c-sources:         cbits/HsUnix.c-        cbits/dirUtils.c         cbits/execvpe.c-        cbits/ghcrts.c