X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FIO%2FDevice.hs;h=bc772b8178ec398ca1aad160b2872d5ae2746b6d;hb=41e8fba828acbae1751628af50849f5352b27873;hp=5010fefc5b8c125bf936b4e0928266e052689a31;hpb=5bea16bf551dd337725af4a3a7640641eb11f5e9;p=ghc-base.git diff --git a/GHC/IO/Device.hs b/GHC/IO/Device.hs index 5010fef..bc772b8 100644 --- a/GHC/IO/Device.hs +++ b/GHC/IO/Device.hs @@ -1,5 +1,5 @@ -{-# OPTIONS_GHC -XNoImplicitPrelude -XBangPatterns #-} -{-# OPTIONS_HADDOCK hide #-} +{-# LANGUAGE CPP, NoImplicitPrelude, BangPatterns #-} + ----------------------------------------------------------------------------- -- | -- Module : GHC.IO.Device @@ -85,7 +85,7 @@ class IODevice a where isSeekable :: a -> IO Bool isSeekable _ = return False - -- | seek to the specified positing in the data. + -- | seek to the specified position in the data. seek :: a -> SeekMode -> Integer -> IO () seek _ _ _ = ioe_unsupportedOperation @@ -133,17 +133,41 @@ class IODevice a where ioe_unsupportedOperation :: IO a ioe_unsupportedOperation = throwIO unsupportedOperation +-- | Type of a device that can be used to back a +-- 'GHC.IO.Handle.Handle' (see also 'GHC.IO.Handle.mkFileHandle'). The +-- standard libraries provide creation of 'GHC.IO.Handle.Handle's via +-- Posix file operations with file descriptors (see +-- 'GHC.IO.Handle.FD.mkHandleFromFD') with FD being the underlying +-- 'GHC.IO.Device.IODevice' instance. +-- +-- Users may provide custom instances of 'GHC.IO.Device.IODevice' +-- which are expected to conform the following rules: + data IODeviceType - = Directory - | Stream - | RegularFile - | RawDevice + = Directory -- ^ The standard libraries do not have direct support + -- for this device type, but a user implementation is + -- expected to provide a list of file names in + -- the directory, in any order, separated by @'\0'@ + -- characters, excluding the @"."@ and @".."@ names. See + -- also 'System.Directory.getDirectoryContents'. Seek + -- operations are not supported on directories (other + -- than to the zero position). + | Stream -- ^ A duplex communications channel (results in + -- creation of a duplex 'GHC.IO.Handle.Handle'). The + -- standard libraries use this device type when + -- creating 'GHC.IO.Handle.Handle's for open sockets. + | RegularFile -- ^ A file that may be read or written, and also + -- may be seekable. + | RawDevice -- ^ A "raw" (disk) device which supports block binary + -- read and write operations and may be seekable only + -- to positions of certain granularity (block- + -- aligned). deriving (Eq) -- ----------------------------------------------------------------------------- -- SeekMode type --- | A mode that determines the effect of 'hSeek' @hdl mode i@, as follows: +-- | A mode that determines the effect of 'hSeek' @hdl mode i@. data SeekMode = AbsoluteSeek -- ^ the position of @hdl@ is set to @i@. | RelativeSeek -- ^ the position of @hdl@ is set to offset @i@