diff options
author | Simon Marlow <marlowsd@gmail.com> | 2011-11-11 16:18:48 +0000 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2011-11-22 12:36:48 +0000 |
commit | 34c7bf896f19b182cf6fa104e057f1df9df1254a (patch) | |
tree | abdb8264ae52c62263fc0fb4b395906a64acb104 /System/Posix/Directory.hsc | |
parent | c213ae2ec6d9c71266aebc8e5b2326a9625fba7a (diff) |
Provide a raw ByteString version of FilePath and environment APIs
The new module System.Posix.ByteString provides exactly the same API
as System.Posix, except that:
- There is a new type: RawFilePath = ByteString
- All functions mentioning FilePath in the System.Posix API
use RawFilePath in the System.Posix.ByteString API
- RawFilePaths are not subject to Unicode locale encoding and
decoding, unlike FilePaths. They are the exact bytes passed to and
returned from the underlying POSIX API.
- Similarly for functions that deal in environment
strings (System.Posix.Env): these use untranslated ByteStrings
in System.Posix.Environment
- There is a new function
System.Posix.ByteString.getArgs :: [ByteString]
returning the raw untranslated arguments as passed to exec() when
the program was started.
Diffstat (limited to 'System/Posix/Directory.hsc')
-rw-r--r-- | System/Posix/Directory.hsc | 59 |
1 files changed, 6 insertions, 53 deletions
diff --git a/System/Posix/Directory.hsc b/System/Posix/Directory.hsc index 48e7390..870795b 100644 --- a/System/Posix/Directory.hsc +++ b/System/Posix/Directory.hsc @@ -3,9 +3,10 @@ #if __GLASGOW_HASKELL__ >= 701 {-# LANGUAGE Trustworthy #-} #endif + ----------------------------------------------------------------------------- -- | --- Module : System.Posix.Files +-- Module : System.Posix.Directory -- Copyright : (c) The University of Glasgow 2002 -- License : BSD-style (see the file libraries/base/LICENSE) -- @@ -13,7 +14,7 @@ -- Stability : provisional -- Portability : non-portable (requires POSIX) -- --- POSIX directory support +-- String-based POSIX directory support -- ----------------------------------------------------------------------------- @@ -42,6 +43,9 @@ import System.Posix.Error import System.Posix.Types import Foreign import Foreign.C + +import System.Posix.Directory.Common + #if __GLASGOW_HASKELL__ > 700 import System.Posix.Internals (withFilePath, peekFilePath) #elif __GLASGOW_HASKELL__ > 611 @@ -70,8 +74,6 @@ createDirectory name mode = foreign import ccall unsafe "mkdir" c_mkdir :: CString -> CMode -> IO CInt -newtype DirStream = DirStream (Ptr CDir) - -- | @openDirStream dir@ calls @opendir@ to obtain a -- directory stream for @dir@. openDirStream :: FilePath -> IO DirStream @@ -109,9 +111,6 @@ readDirStream (DirStream dirp) = then return [] else throwErrno "readDirStream" -type CDir = () -type CDirent = () - -- traversing directories foreign import ccall unsafe "__hscore_readdir" c_readdir :: Ptr CDir -> Ptr (Ptr CDirent) -> IO CInt @@ -122,45 +121,6 @@ foreign import ccall unsafe "__hscore_free_dirent" foreign import ccall unsafe "__hscore_d_name" d_name :: Ptr CDirent -> IO CString --- | @rewindDirStream dp@ calls @rewinddir@ to reposition --- the directory stream @dp@ at the beginning of the directory. -rewindDirStream :: DirStream -> IO () -rewindDirStream (DirStream dirp) = c_rewinddir dirp - -foreign import ccall unsafe "rewinddir" - c_rewinddir :: Ptr CDir -> IO () - --- | @closeDirStream dp@ calls @closedir@ to close --- the directory stream @dp@. -closeDirStream :: DirStream -> IO () -closeDirStream (DirStream dirp) = do - throwErrnoIfMinus1Retry_ "closeDirStream" (c_closedir dirp) - -foreign import ccall unsafe "closedir" - c_closedir :: Ptr CDir -> IO CInt - -newtype DirStreamOffset = DirStreamOffset COff - -seekDirStream :: DirStream -> DirStreamOffset -> IO () -seekDirStream (DirStream dirp) (DirStreamOffset off) = - c_seekdir dirp off - -foreign import ccall unsafe "seekdir" - c_seekdir :: Ptr CDir -> COff -> IO () - -tellDirStream :: DirStream -> IO DirStreamOffset -tellDirStream (DirStream dirp) = do - off <- c_telldir dirp - return (DirStreamOffset off) - -foreign import ccall unsafe "telldir" - c_telldir :: Ptr CDir -> IO COff - -{- - Renamings of functionality provided via Directory interface, - kept around for b.wards compatibility and for having more POSIXy - names --} -- | @getWorkingDirectory@ calls @getcwd@ to obtain the name -- of the current working directory. @@ -206,10 +166,3 @@ removeDirectory path = foreign import ccall unsafe "rmdir" c_rmdir :: CString -> IO CInt - -changeWorkingDirectoryFd :: Fd -> IO () -changeWorkingDirectoryFd (Fd fd) = - throwErrnoIfMinus1Retry_ "changeWorkingDirectoryFd" (c_fchdir fd) - -foreign import ccall unsafe "fchdir" - c_fchdir :: CInt -> IO CInt |