Language-Haskell
view release on metacpan or search on metacpan
hugs98-Nov2003/fptools/libraries/unix/System/Posix/Files.hsc view on Meta::CPAN
throwErrnoIfMinus1_ "createDevice" (c_mknod s mode dev)
foreign import ccall unsafe "mknod"
c_mknod :: CString -> CMode -> CDev -> IO CInt
-- -----------------------------------------------------------------------------
-- Hard links
createLink :: FilePath -> FilePath -> IO ()
createLink name1 name2 =
withCString name1 $ \s1 ->
withCString name2 $ \s2 ->
throwErrnoIfMinus1_ "createLink" (c_link s1 s2)
removeLink :: FilePath -> IO ()
removeLink name =
withCString name $ \s ->
throwErrnoIfMinus1_ "removeLink" (c_unlink s)
-- -----------------------------------------------------------------------------
-- Symbolic Links
createSymbolicLink :: FilePath -> FilePath -> IO ()
createSymbolicLink file1 file2 =
withCString file1 $ \s1 ->
withCString file2 $ \s2 ->
throwErrnoIfMinus1_ "createSymbolicLink" (c_symlink s1 s2)
foreign import ccall unsafe "symlink"
c_symlink :: CString -> CString -> IO CInt
-- ToDo: should really use SYMLINK_MAX, but not everyone supports it yet,
-- and it seems that the intention is that SYMLINK_MAX is no larger than
-- PATH_MAX.
readSymbolicLink :: FilePath -> IO FilePath
readSymbolicLink file =
allocaArray0 (#const PATH_MAX) $ \buf -> do
withCString file $ \s -> do
len <- throwErrnoIfMinus1 "readSymbolicLink" $
c_readlink s buf (#const PATH_MAX)
peekCStringLen (buf,fromIntegral len)
foreign import ccall unsafe "readlink"
c_readlink :: CString -> CString -> CInt -> IO CInt
-- -----------------------------------------------------------------------------
-- Renaming files
rename :: FilePath -> FilePath -> IO ()
rename name1 name2 =
withCString name1 $ \s1 ->
withCString name2 $ \s2 ->
throwErrnoIfMinus1_ "rename" (c_rename s1 s2)
-- -----------------------------------------------------------------------------
-- chmod()
setOwnerAndGroup :: FilePath -> UserID -> GroupID -> IO ()
setOwnerAndGroup name uid gid = do
withCString name $ \s ->
throwErrnoIfMinus1_ "setOwnerAndGroup" (c_chown s uid gid)
foreign import ccall unsafe "chown"
c_chown :: CString -> CUid -> CGid -> IO CInt
setFdOwnerAndGroup :: Fd -> UserID -> GroupID -> IO ()
setFdOwnerAndGroup (Fd fd) uid gid =
throwErrnoIfMinus1_ "setFdOwnerAndGroup" (c_fchown fd uid gid)
foreign import ccall unsafe "fchown"
c_fchown :: CInt -> CUid -> CGid -> IO CInt
#if HAVE_LCHOWN
setSymbolicLinkOwnerAndGroup :: FilePath -> UserID -> GroupID -> IO ()
setSymbolicLinkOwnerAndGroup name uid gid = do
withCString name $ \s ->
throwErrnoIfMinus1_ "setSymbolicLinkOwnerAndGroup" (c_lchown s uid gid)
foreign import ccall unsafe "lchown"
c_lchown :: CString -> CUid -> CGid -> IO CInt
#endif
-- -----------------------------------------------------------------------------
-- utime()
setFileTimes :: FilePath -> EpochTime -> EpochTime -> IO ()
setFileTimes name atime mtime = do
withCString name $ \s ->
allocaBytes (#const sizeof(struct utimbuf)) $ \p -> do
(#poke struct utimbuf, actime) p atime
(#poke struct utimbuf, modtime) p mtime
throwErrnoIfMinus1_ "setFileTimes" (c_utime s p)
touchFile :: FilePath -> IO ()
touchFile name = do
withCString name $ \s ->
throwErrnoIfMinus1_ "touchFile" (c_utime s nullPtr)
-- -----------------------------------------------------------------------------
-- Setting file sizes
setFileSize :: FilePath -> FileOffset -> IO ()
setFileSize file off =
withCString file $ \s ->
throwErrnoIfMinus1_ "setFileSize" (c_truncate s off)
foreign import ccall unsafe "truncate"
c_truncate :: CString -> COff -> IO CInt
setFdSize :: Fd -> FileOffset -> IO ()
setFdSize fd off =
throwErrnoIfMinus1_ "setFdSize" (c_ftruncate fd off)
foreign import ccall unsafe "ftruncate"
c_ftruncate :: Fd -> COff -> IO CInt
-- -----------------------------------------------------------------------------
-- pathconf()/fpathconf() support
data PathVar
= FileSizeBits {- _PC_FILESIZEBITS -}
| LinkLimit {- _PC_LINK_MAX -}
| InputLineLimit {- _PC_MAX_CANON -}
| InputQueueLimit {- _PC_MAX_INPUT -}
| FileNameLimit {- _PC_NAME_MAX -}
| PathNameLimit {- _PC_PATH_MAX -}
| PipeBufferLimit {- _PC_PIPE_BUF -}
-- These are described as optional in POSIX:
{- _PC_ALLOC_SIZE_MIN -}
{- _PC_REC_INCR_XFER_SIZE -}
{- _PC_REC_MAX_XFER_SIZE -}
{- _PC_REC_MIN_XFER_SIZE -}
{- _PC_REC_XFER_ALIGN -}
| SymbolicLinkLimit {- _PC_SYMLINK_MAX -}
| SetOwnerAndGroupIsRestricted {- _PC_CHOWN_RESTRICTED -}
| FileNamesAreNotTruncated {- _PC_NO_TRUNC -}
| VDisableChar {- _PC_VDISABLE -}
| AsyncIOAvailable {- _PC_ASYNC_IO -}
| PrioIOAvailable {- _PC_PRIO_IO -}
| SyncIOAvailable {- _PC_SYNC_IO -}
( run in 0.873 second using v1.01-cache-2.11-cpan-71847e10f99 )