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) |
Safe Haskell | Safe |
Language | Haskell2010 |
System.Posix.IO.ByteString
Description
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.
Synopsis
- stdInput :: Fd
- stdOutput :: Fd
- stdError :: Fd
- dataOpenMode
- dataOpenFileFlags = OpenFileFlags {}
- defaultFileFlags :: OpenFileFlags
- openFd :: RawFilePath -> OpenMode -> MaybeFileMode -> OpenFileFlags -> IOFd
- createFile :: RawFilePath -> FileMode -> IOFd
- closeFd :: Fd -> IO ()
- fdRead :: Fd -> ByteCount -> IO (String, ByteCount)
- fdWrite :: Fd -> String -> IOByteCount
- fdReadBuf :: Fd -> PtrWord8 -> ByteCount -> IOByteCount
- fdWriteBuf :: Fd -> PtrWord8 -> ByteCount -> IOByteCount
- fdSeek :: Fd -> SeekMode -> FileOffset -> IOFileOffset
- dataFdOption
- queryFdOption :: Fd -> FdOption -> IOBool
- setFdOption :: Fd -> FdOption -> Bool -> IO ()
- typeFileLock = (LockRequest, SeekMode, FileOffset, FileOffset)
- dataLockRequest
- getLock :: Fd -> FileLock -> IO (Maybe (ProcessID, FileLock))
- setLock :: Fd -> FileLock -> IO ()
- waitToSetLock :: Fd -> FileLock -> IO ()
- createPipe :: IO (Fd, Fd)
- dup :: Fd -> IOFd
- dupTo :: Fd -> Fd -> IOFd
- handleToFd :: Handle -> IOFd
- fdToHandle :: Fd -> IOHandle
Input / Output
Standard file descriptors
Opening and closing files
Correspond to some of the int flags from C's fcntl.h.
defaultFileFlags :: OpenFileFlagsSource#
Default values for the OpenFileFlags
type. False for each of append, exclusive, noctty, nonBlock, and trunc.
Arguments
:: RawFilePath | |
-> OpenMode | |
-> MaybeFileMode | Just x => creates the file with the given modes, Nothing => the file must exist. |
-> OpenFileFlags | |
-> IOFd |
createFile :: RawFilePath -> FileMode -> IOFdSource#
closeFd :: Fd -> IO () Source#
Close this file descriptor. May throw an exception if this is an invalid descriptor.
Reading/writing data
Programmers using the fdRead
and fdWrite
API should be aware that EAGAIN exceptions may occur for non-blocking IO!
Arguments
:: Fd | |
-> PtrWord8 | Memory in which to put the data |
-> ByteCount | Maximum number of bytes to read |
-> IOByteCount | Number of bytes read (zero for EOF) |
Read data from an Fd
into memory. This is exactly equivalent to the POSIX read
function.
Arguments
:: Fd | |
-> PtrWord8 | Memory containing the data to write |
-> ByteCount | Maximum number of bytes to write |
-> IOByteCount | Number of bytes written |
Write data from memory to an Fd
. This is exactly equivalent to the POSIX write
function.
Seeking
fdSeek :: Fd -> SeekMode -> FileOffset -> IOFileOffsetSource#
May throw an exception if this is an invalid descriptor.
File options
Constructors
AppendOnWrite | O_APPEND |
CloseOnExec | FD_CLOEXEC |
NonBlockingRead | O_NONBLOCK |
SynchronousWrites | O_SYNC |
queryFdOption :: Fd -> FdOption -> IOBoolSource#
May throw an exception if this is an invalid descriptor.
setFdOption :: Fd -> FdOption -> Bool -> IO () Source#
May throw an exception if this is an invalid descriptor.
Locking
typeFileLock = (LockRequest, SeekMode, FileOffset, FileOffset) Source#
getLock :: Fd -> FileLock -> IO (Maybe (ProcessID, FileLock)) Source#
May throw an exception if this is an invalid descriptor.
waitToSetLock :: Fd -> FileLock -> IO () Source#
May throw an exception if this is an invalid descriptor.
Pipes
createPipe :: IO (Fd, Fd) Source#
The createPipe
function creates a pair of connected file descriptors. The first component is the fd to read from, the second is the write end. Although pipes may be bidirectional, this behaviour is not portable and programmers should use two separate pipes for this purpose. May throw an exception if this is an invalid descriptor.