{-# LINE 1 "System/Posix/Files/ByteString.hsc" #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE PatternSynonyms #-}
module System.Posix.Files.ByteString (
unionFileModes, intersectFileModes,
nullFileMode,
ownerReadMode, ownerWriteMode, ownerExecuteMode, ownerModes,
groupReadMode, groupWriteMode, groupExecuteMode, groupModes,
otherReadMode, otherWriteMode, otherExecuteMode, otherModes,
setUserIDMode, setGroupIDMode,
stdFileMode, accessModes,
fileTypeModes,
blockSpecialMode, characterSpecialMode, namedPipeMode, regularFileMode,
directoryMode, symbolicLinkMode, socketMode,
setFileMode, setFdMode, setFileCreationMask,
fileAccess, fileExist,
FileStatus,
getFileStatus, getFdStatus, getSymbolicLinkStatus,
deviceID, fileID, fileMode, linkCount, fileOwner, fileGroup,
specialDeviceID, fileSize, accessTime, modificationTime,
statusChangeTime,
accessTimeHiRes, modificationTimeHiRes, statusChangeTimeHiRes,
isBlockDevice, isCharacterDevice, isNamedPipe, isRegularFile,
isDirectory, isSymbolicLink, isSocket,
fileBlockSize,
fileBlocks,
ExtendedFileStatus(..),
CAttributes(..),
haveStatx,
getExtendedFileStatus,
StatxFlags(..),
defaultStatxFlags,
pattern EmptyPath,
pattern NoAutoMount,
pattern SymlinkNoFollow,
pattern SyncAsStat,
pattern ForceSync,
pattern DontSync,
StatxMask(..),
defaultStatxMask,
pattern StatxType,
pattern StatxMode,
pattern StatxNlink,
pattern StatxUid,
pattern StatxGid,
pattern StatxAtime,
pattern StatxMtime,
pattern StatxCtime,
pattern StatxIno,
pattern StatxSize,
pattern StatxBlocks,
pattern StatxBasicStats,
pattern StatxBtime,
pattern StatxMntId,
pattern StatxAll,
fileBlockSizeX,
linkCountX,
fileOwnerX,
fileGroupX,
fileModeX,
fileIDX,
fileSizeX,
fileBlocksX,
accessTimeHiResX,
creationTimeHiResX,
statusChangeTimeHiResX,
modificationTimeHiResX,
deviceIDX,
specialDeviceIDX,
mountIDX,
fileCompressedX,
fileImmutableX,
fileAppendX,
fileNoDumpX,
fileEncryptedX,
fileVerityX,
fileDaxX,
isBlockDeviceX,
isCharacterDeviceX,
isNamedPipeX,
isRegularFileX,
isDirectoryX,
isSymbolicLinkX,
isSocketX,
createNamedPipe,
createDevice,
createLink, removeLink,
createSymbolicLink, readSymbolicLink,
rename,
setOwnerAndGroup, setFdOwnerAndGroup,
{-# LINE 146 "System/Posix/Files/ByteString.hsc" #-}
setSymbolicLinkOwnerAndGroup,
{-# LINE 148 "System/Posix/Files/ByteString.hsc" #-}
setFileTimes, setFileTimesHiRes,
setFdTimesHiRes, setSymbolicLinkTimesHiRes,
touchFile, touchFd, touchSymbolicLink,
setFileSize, setFdSize,
PathVar(..), getPathVar, getFdPathVar,
) where
import System.Posix.Types
import System.Posix.Internals hiding (withFilePath, peekFilePathLen)
import Foreign
import Foreign.C hiding (
throwErrnoPath,
throwErrnoPathIf,
throwErrnoPathIf_,
throwErrnoPathIfNull,
throwErrnoPathIfMinus1,
throwErrnoPathIfMinus1_ )
import System.Posix.Files.Common
import System.Posix.ByteString.FilePath
import Data.Time.Clock.POSIX (POSIXTime)
{-# LINE 181 "System/Posix/Files/ByteString.hsc" #-}
setFileMode :: RawFilePath -> FileMode -> IO ()
setFileMode :: RawFilePath -> CMode -> IO ()
setFileMode RawFilePath
name CMode
m =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s -> do
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"setFileMode" RawFilePath
name (CString -> CMode -> IO CInt
c_chmod CString
s CMode
m)
fileAccess :: RawFilePath -> Bool -> Bool -> Bool -> IO Bool
fileAccess :: RawFilePath -> Bool -> Bool -> Bool -> IO Bool
fileAccess RawFilePath
name Bool
readOK Bool
writeOK Bool
execOK = RawFilePath -> CMode -> IO Bool
access RawFilePath
name CMode
flags
where
flags :: CMode
flags = CMode
read_f CMode -> CMode -> CMode
forall a. Bits a => a -> a -> a
.|. CMode
write_f CMode -> CMode -> CMode
forall a. Bits a => a -> a -> a
.|. CMode
exec_f
read_f :: CMode
read_f = if Bool
readOK then (CMode
4) else CMode
0
{-# LINE 210 "System/Posix/Files/ByteString.hsc" #-}
write_f = if writeOK then (2) else 0
{-# LINE 211 "System/Posix/Files/ByteString.hsc" #-}
exec_f = if execOK then (1) else 0
{-# LINE 212 "System/Posix/Files/ByteString.hsc" #-}
fileExist :: RawFilePath -> IO Bool
fileExist :: RawFilePath -> IO Bool
fileExist RawFilePath
name =
RawFilePath -> (CString -> IO Bool) -> IO Bool
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
s -> do
CInt
r <- CString -> CInt -> IO CInt
c_access CString
s (CInt
0)
{-# LINE 220 "System/Posix/Files/ByteString.hsc" #-}
if (r == 0)
then return True
else do err <- getErrno
if (err == eNOENT)
then return False
else throwErrnoPath "fileExist" name
access :: RawFilePath -> CMode -> IO Bool
access :: RawFilePath -> CMode -> IO Bool
access RawFilePath
name CMode
flags =
RawFilePath -> (CString -> IO Bool) -> IO Bool
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO Bool) -> IO Bool)
-> (CString -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \CString
s -> do
CInt
r <- CString -> CInt -> IO CInt
c_access CString
s (CMode -> CInt
forall a b. (Integral a, Num b) => a -> b
fromIntegral CMode
flags)
if (CInt
r CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
== CInt
0)
then Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
else do Errno
err <- IO Errno
getErrno
if (Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eACCES Bool -> Bool -> Bool
|| Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eROFS Bool -> Bool -> Bool
|| Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
eTXTBSY Bool -> Bool -> Bool
||
Errno
err Errno -> Errno -> Bool
forall a. Eq a => a -> a -> Bool
== Errno
ePERM)
then Bool -> IO Bool
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
else String -> RawFilePath -> IO Bool
forall a. String -> RawFilePath -> IO a
throwErrnoPath String
"fileAccess" RawFilePath
name
getFileStatus :: RawFilePath -> IO FileStatus
getFileStatus :: RawFilePath -> IO FileStatus
getFileStatus RawFilePath
path = do
ForeignPtr CStat
fp <- Int -> IO (ForeignPtr CStat)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes (Int
144)
{-# LINE 247 "System/Posix/Files/ByteString.hsc" #-}
withForeignPtr fp $ \p ->
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "getFileStatus" path (c_stat s p)
FileStatus -> IO FileStatus
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CStat -> FileStatus
FileStatus ForeignPtr CStat
fp)
getExtendedFileStatus :: Maybe Fd
-> RawFilePath
-> StatxFlags
-> StatxMask
-> IO ExtendedFileStatus
getExtendedFileStatus :: Maybe Fd
-> RawFilePath -> StatxFlags -> StatxMask -> IO ExtendedFileStatus
getExtendedFileStatus Maybe Fd
mfd RawFilePath
path StatxFlags
flags StatxMask
masks = RawFilePath
-> (CString -> IO ExtendedFileStatus) -> IO ExtendedFileStatus
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
path ((CString -> IO ExtendedFileStatus) -> IO ExtendedFileStatus)
-> (CString -> IO ExtendedFileStatus) -> IO ExtendedFileStatus
forall a b. (a -> b) -> a -> b
$ \CString
s -> Maybe Fd
-> CString -> StatxFlags -> StatxMask -> IO ExtendedFileStatus
getExtendedFileStatus_ Maybe Fd
mfd CString
s StatxFlags
flags StatxMask
masks
getSymbolicLinkStatus :: RawFilePath -> IO FileStatus
getSymbolicLinkStatus :: RawFilePath -> IO FileStatus
getSymbolicLinkStatus RawFilePath
path = do
ForeignPtr CStat
fp <- Int -> IO (ForeignPtr CStat)
forall a. Int -> IO (ForeignPtr a)
mallocForeignPtrBytes (Int
144)
{-# LINE 279 "System/Posix/Files/ByteString.hsc" #-}
withForeignPtr fp $ \p ->
withFilePath path $ \s ->
throwErrnoPathIfMinus1_ "getSymbolicLinkStatus" path (c_lstat s p)
FileStatus -> IO FileStatus
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignPtr CStat -> FileStatus
FileStatus ForeignPtr CStat
fp)
foreign import capi unsafe "HsUnix.h lstat"
c_lstat :: CString -> Ptr CStat -> IO CInt
createNamedPipe :: RawFilePath -> FileMode -> IO ()
createNamedPipe :: RawFilePath -> CMode -> IO ()
createNamedPipe RawFilePath
name CMode
mode = do
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"createNamedPipe" RawFilePath
name (CString -> CMode -> IO CInt
c_mkfifo CString
s CMode
mode)
{-# LINE 306 "System/Posix/Files/ByteString.hsc" #-}
createDevice :: RawFilePath -> FileMode -> DeviceID -> IO ()
createDevice :: RawFilePath -> CMode -> DeviceID -> IO ()
createDevice RawFilePath
path CMode
mode DeviceID
dev =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
path ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"createDevice" RawFilePath
path (CString -> CMode -> DeviceID -> IO CInt
c_mknod CString
s CMode
mode DeviceID
dev)
foreign import capi unsafe "HsUnix.h mknod"
c_mknod :: CString -> CMode -> CDev -> IO CInt
{-# LINE 324 "System/Posix/Files/ByteString.hsc" #-}
createLink :: RawFilePath -> RawFilePath -> IO ()
createLink :: RawFilePath -> RawFilePath -> IO ()
createLink RawFilePath
name1 RawFilePath
name2 =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name1 ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s1 ->
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name2 ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s2 ->
String -> RawFilePath -> RawFilePath -> IO CInt -> IO ()
forall a.
(Eq a, Num a) =>
String -> RawFilePath -> RawFilePath -> IO a -> IO ()
throwErrnoTwoPathsIfMinus1_ String
"createLink" RawFilePath
name1 RawFilePath
name2 (CString -> CString -> IO CInt
c_link CString
s1 CString
s2)
removeLink :: RawFilePath -> IO ()
removeLink :: RawFilePath -> IO ()
removeLink RawFilePath
name =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"removeLink" RawFilePath
name (CString -> IO CInt
c_unlink CString
s)
createSymbolicLink :: RawFilePath -> RawFilePath -> IO ()
createSymbolicLink :: RawFilePath -> RawFilePath -> IO ()
createSymbolicLink RawFilePath
name1 RawFilePath
name2 =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name1 ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s1 ->
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name2 ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s2 ->
String -> RawFilePath -> RawFilePath -> IO CInt -> IO ()
forall a.
(Eq a, Num a) =>
String -> RawFilePath -> RawFilePath -> IO a -> IO ()
throwErrnoTwoPathsIfMinus1_ String
"createSymbolicLink" RawFilePath
name1 RawFilePath
name2 (CString -> CString -> IO CInt
c_symlink CString
s1 CString
s2)
foreign import ccall unsafe "symlink"
c_symlink :: CString -> CString -> IO CInt
{-# LINE 373 "System/Posix/Files/ByteString.hsc" #-}
readSymbolicLink :: RawFilePath -> IO RawFilePath
readSymbolicLink :: RawFilePath -> IO RawFilePath
readSymbolicLink RawFilePath
file =
Int -> (CString -> IO RawFilePath) -> IO RawFilePath
forall a b. Storable a => Int -> (Ptr a -> IO b) -> IO b
allocaArray0 (Int
4096) ((CString -> IO RawFilePath) -> IO RawFilePath)
-> (CString -> IO RawFilePath) -> IO RawFilePath
forall a b. (a -> b) -> a -> b
$ \CString
buf -> do
{-# LINE 380 "System/Posix/Files/ByteString.hsc" #-}
withFilePath file $ \s -> do
len <- throwErrnoPathIfMinus1 "readSymbolicLink" file $
c_readlink s buf (4096)
{-# LINE 383 "System/Posix/Files/ByteString.hsc" #-}
peekFilePathLen (buf,fromIntegral len)
foreign import ccall unsafe "readlink"
c_readlink :: CString -> CString -> CSize -> IO CInt
rename :: RawFilePath -> RawFilePath -> IO ()
rename :: RawFilePath -> RawFilePath -> IO ()
rename RawFilePath
name1 RawFilePath
name2 =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name1 ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s1 ->
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name2 ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s2 ->
String -> RawFilePath -> RawFilePath -> IO CInt -> IO ()
forall a.
(Eq a, Num a) =>
String -> RawFilePath -> RawFilePath -> IO a -> IO ()
throwErrnoTwoPathsIfMinus1_ String
"rename" RawFilePath
name1 RawFilePath
name2 (CString -> CString -> IO CInt
c_rename CString
s1 CString
s2)
foreign import ccall unsafe "rename"
c_rename :: CString -> CString -> IO CInt
{-# LINE 407 "System/Posix/Files/ByteString.hsc" #-}
setOwnerAndGroup :: RawFilePath -> UserID -> GroupID -> IO ()
setOwnerAndGroup :: RawFilePath -> UserID -> GroupID -> IO ()
setOwnerAndGroup RawFilePath
name UserID
uid GroupID
gid = do
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"setOwnerAndGroup" RawFilePath
name (CString -> UserID -> GroupID -> IO CInt
c_chown CString
s UserID
uid GroupID
gid)
foreign import ccall unsafe "chown"
c_chown :: CString -> CUid -> CGid -> IO CInt
{-# LINE 429 "System/Posix/Files/ByteString.hsc" #-}
{-# LINE 431 "System/Posix/Files/ByteString.hsc" #-}
setSymbolicLinkOwnerAndGroup :: RawFilePath -> UserID -> GroupID -> IO ()
setSymbolicLinkOwnerAndGroup :: RawFilePath -> UserID -> GroupID -> IO ()
setSymbolicLinkOwnerAndGroup RawFilePath
name UserID
uid GroupID
gid = do
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"setSymbolicLinkOwnerAndGroup" RawFilePath
name
(CString -> UserID -> GroupID -> IO CInt
c_lchown CString
s UserID
uid GroupID
gid)
foreign import ccall unsafe "lchown"
c_lchown :: CString -> CUid -> CGid -> IO CInt
{-# LINE 444 "System/Posix/Files/ByteString.hsc" #-}
setFileTimes :: RawFilePath -> EpochTime -> EpochTime -> IO ()
setFileTimes :: RawFilePath -> EpochTime -> EpochTime -> IO ()
setFileTimes RawFilePath
name EpochTime
atime EpochTime
mtime = do
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
Int -> (Ptr CUtimbuf -> IO ()) -> IO ()
forall a b. Int -> (Ptr a -> IO b) -> IO b
allocaBytes (Int
16) ((Ptr CUtimbuf -> IO ()) -> IO ())
-> (Ptr CUtimbuf -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CUtimbuf
p -> do
{-# LINE 456 "System/Posix/Files/ByteString.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 0)) p atime
{-# LINE 457 "System/Posix/Files/ByteString.hsc" #-}
((\hsc_ptr -> pokeByteOff hsc_ptr 8)) p mtime
{-# LINE 458 "System/Posix/Files/ByteString.hsc" #-}
throwErrnoPathIfMinus1_ "setFileTimes" name (c_utime s p)
setFileTimesHiRes :: RawFilePath -> POSIXTime -> POSIXTime -> IO ()
{-# LINE 474 "System/Posix/Files/ByteString.hsc" #-}
setFileTimesHiRes :: RawFilePath -> POSIXTime -> POSIXTime -> IO ()
setFileTimesHiRes RawFilePath
name POSIXTime
atime POSIXTime
mtime =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
[CTimeSpec] -> (Ptr CTimeSpec -> IO ()) -> IO ()
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray [POSIXTime -> CTimeSpec
toCTimeSpec POSIXTime
atime, POSIXTime -> CTimeSpec
toCTimeSpec POSIXTime
mtime] ((Ptr CTimeSpec -> IO ()) -> IO ())
-> (Ptr CTimeSpec -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CTimeSpec
times ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"setFileTimesHiRes" RawFilePath
name (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
CInt -> CString -> Ptr CTimeSpec -> CInt -> IO CInt
c_utimensat (-CInt
100) CString
s Ptr CTimeSpec
times CInt
0
{-# LINE 479 "System/Posix/Files/ByteString.hsc" #-}
{-# LINE 485 "System/Posix/Files/ByteString.hsc" #-}
setSymbolicLinkTimesHiRes :: RawFilePath -> POSIXTime -> POSIXTime -> IO ()
{-# LINE 502 "System/Posix/Files/ByteString.hsc" #-}
setSymbolicLinkTimesHiRes :: RawFilePath -> POSIXTime -> POSIXTime -> IO ()
setSymbolicLinkTimesHiRes RawFilePath
name POSIXTime
atime POSIXTime
mtime =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
[CTimeSpec] -> (Ptr CTimeSpec -> IO ()) -> IO ()
forall a b. Storable a => [a] -> (Ptr a -> IO b) -> IO b
withArray [POSIXTime -> CTimeSpec
toCTimeSpec POSIXTime
atime, POSIXTime -> CTimeSpec
toCTimeSpec POSIXTime
mtime] ((Ptr CTimeSpec -> IO ()) -> IO ())
-> (Ptr CTimeSpec -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr CTimeSpec
times ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"setSymbolicLinkTimesHiRes" RawFilePath
name (IO CInt -> IO ()) -> IO CInt -> IO ()
forall a b. (a -> b) -> a -> b
$
CInt -> CString -> Ptr CTimeSpec -> CInt -> IO CInt
c_utimensat (-CInt
100) CString
s Ptr CTimeSpec
times (CInt
256)
{-# LINE 507 "System/Posix/Files/ByteString.hsc" #-}
{-# LINE 518 "System/Posix/Files/ByteString.hsc" #-}
touchFile :: RawFilePath -> IO ()
touchFile :: RawFilePath -> IO ()
touchFile RawFilePath
name = do
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"touchFile" RawFilePath
name (CString -> Ptr CUtimbuf -> IO CInt
c_utime CString
s Ptr CUtimbuf
forall a. Ptr a
nullPtr)
touchSymbolicLink :: RawFilePath -> IO ()
{-# LINE 539 "System/Posix/Files/ByteString.hsc" #-}
touchSymbolicLink :: RawFilePath -> IO ()
touchSymbolicLink RawFilePath
name =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"touchSymbolicLink" RawFilePath
name (CString -> Ptr CTimeVal -> IO CInt
c_lutimes CString
s Ptr CTimeVal
forall a. Ptr a
nullPtr)
{-# LINE 547 "System/Posix/Files/ByteString.hsc" #-}
setFileSize :: RawFilePath -> FileOffset -> IO ()
setFileSize :: RawFilePath -> FileOffset -> IO ()
setFileSize RawFilePath
file FileOffset
off =
RawFilePath -> (CString -> IO ()) -> IO ()
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
file ((CString -> IO ()) -> IO ()) -> (CString -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \CString
s ->
String -> RawFilePath -> IO CInt -> IO ()
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO ()
throwErrnoPathIfMinus1_ String
"setFileSize" RawFilePath
file (CString -> FileOffset -> IO CInt
c_truncate CString
s FileOffset
off)
foreign import capi unsafe "HsUnix.h truncate"
c_truncate :: CString -> COff -> IO CInt
getPathVar :: RawFilePath -> PathVar -> IO Limit
getPathVar :: RawFilePath -> PathVar -> IO CLong
getPathVar RawFilePath
name PathVar
v = do
RawFilePath -> (CString -> IO CLong) -> IO CLong
forall a. RawFilePath -> (CString -> IO a) -> IO a
withFilePath RawFilePath
name ((CString -> IO CLong) -> IO CLong)
-> (CString -> IO CLong) -> IO CLong
forall a b. (a -> b) -> a -> b
$ \ CString
nameP ->
String -> RawFilePath -> IO CLong -> IO CLong
forall a. (Eq a, Num a) => String -> RawFilePath -> IO a -> IO a
throwErrnoPathIfMinus1 String
"getPathVar" RawFilePath
name (IO CLong -> IO CLong) -> IO CLong -> IO CLong
forall a b. (a -> b) -> a -> b
$
CString -> CInt -> IO CLong
c_pathconf CString
nameP (PathVar -> CInt
pathVarConst PathVar
v)
foreign import ccall unsafe "pathconf"
c_pathconf :: CString -> CInt -> IO CLong