93 lines
2.3 KiB
Plaintext
93 lines
2.3 KiB
Plaintext
|
#if __GLASGOW_HASKELL__ >= 709
|
||
|
{-# LANGUAGE Safe #-}
|
||
|
#else
|
||
|
{-# LANGUAGE Trustworthy #-}
|
||
|
#endif
|
||
|
-----------------------------------------------------------------------------
|
||
|
-- |
|
||
|
-- 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)
|
||
|
--
|
||
|
-- POSIX IO support. These types and functions correspond to the unix
|
||
|
-- functions open(2), close(2), etc. For more portable functions
|
||
|
-- which are more like fopen(3) and friends from stdio.h, see
|
||
|
-- "System.IO".
|
||
|
--
|
||
|
-----------------------------------------------------------------------------
|
||
|
|
||
|
#include "HsUnix.h"
|
||
|
|
||
|
module System.Posix.IO.ByteString (
|
||
|
-- * Input \/ Output
|
||
|
|
||
|
-- ** Standard file descriptors
|
||
|
stdInput, stdOutput, stdError,
|
||
|
|
||
|
-- ** Opening and closing files
|
||
|
OpenMode(..),
|
||
|
OpenFileFlags(..), defaultFileFlags,
|
||
|
openFd, createFile,
|
||
|
closeFd,
|
||
|
|
||
|
-- ** Reading\/writing data
|
||
|
-- |Programmers using the 'fdRead' and 'fdWrite' API should be aware that
|
||
|
-- EAGAIN exceptions may occur for non-blocking IO!
|
||
|
|
||
|
fdRead, fdWrite,
|
||
|
fdReadBuf, fdWriteBuf,
|
||
|
|
||
|
-- ** Seeking
|
||
|
fdSeek,
|
||
|
|
||
|
-- ** File options
|
||
|
FdOption(..),
|
||
|
queryFdOption,
|
||
|
setFdOption,
|
||
|
|
||
|
-- ** Locking
|
||
|
FileLock,
|
||
|
LockRequest(..),
|
||
|
getLock, setLock,
|
||
|
waitToSetLock,
|
||
|
|
||
|
-- ** Pipes
|
||
|
createPipe,
|
||
|
|
||
|
-- ** Duplicating file descriptors
|
||
|
dup, dupTo,
|
||
|
|
||
|
-- ** Converting file descriptors to\/from Handles
|
||
|
handleToFd,
|
||
|
fdToHandle,
|
||
|
|
||
|
) where
|
||
|
|
||
|
import System.Posix.Types
|
||
|
import System.Posix.IO.Common
|
||
|
|
||
|
import System.Posix.ByteString.FilePath
|
||
|
|
||
|
-- |Open and optionally create this file. See 'System.Posix.Files'
|
||
|
-- for information on how to use the 'FileMode' type.
|
||
|
openFd :: RawFilePath
|
||
|
-> OpenMode
|
||
|
-> OpenFileFlags
|
||
|
-> IO Fd
|
||
|
openFd name how flags =
|
||
|
withFilePath name $ \str ->
|
||
|
throwErrnoPathIfMinus1Retry "openFd" name $
|
||
|
open_ str how flags
|
||
|
|
||
|
-- |Create and open this file in WriteOnly mode. A special case of
|
||
|
-- 'openFd'. See 'System.Posix.Files' for information on how to use
|
||
|
-- the 'FileMode' type.
|
||
|
|
||
|
createFile :: RawFilePath -> FileMode -> IO Fd
|
||
|
createFile name mode
|
||
|
= openFd name WriteOnly defaultFileFlags{ trunc=True, creat=(Just mode) }
|