{-# LINE 1 "System/Posix/Fcntl.hsc" #-}
{-# LANGUAGE CApiFFI #-}
{-# LANGUAGE Safe #-}
module System.Posix.Fcntl (
Advice(..), fileAdvise,
fileAllocate,
) where
{-# LINE 27 "System/Posix/Fcntl.hsc" #-}
import Foreign.C
{-# LINE 29 "System/Posix/Fcntl.hsc" #-}
import System.Posix.Types
{-# LINE 35 "System/Posix/Fcntl.hsc" #-}
data Advice
= AdviceNormal
| AdviceRandom
| AdviceSequential
| AdviceWillNeed
| AdviceDontNeed
| AdviceNoReuse
deriving Advice -> Advice -> Bool
(Advice -> Advice -> Bool)
-> (Advice -> Advice -> Bool) -> Eq Advice
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Advice -> Advice -> Bool
== :: Advice -> Advice -> Bool
$c/= :: Advice -> Advice -> Bool
/= :: Advice -> Advice -> Bool
Eq
fileAdvise :: Fd -> FileOffset -> FileOffset -> Advice -> IO ()
{-# LINE 63 "System/Posix/Fcntl.hsc" #-}
fileAdvise fd off len adv = do
throwErrnoIfMinus1_ "fileAdvise" (c_posix_fadvise (fromIntegral fd) (fromIntegral off) (fromIntegral len) (packAdvice adv))
foreign import capi safe "fcntl.h posix_fadvise"
c_posix_fadvise :: CInt -> COff -> COff -> CInt -> IO CInt
packAdvice :: Advice -> CInt
packAdvice :: Advice -> CInt
packAdvice Advice
AdviceNormal = (CInt
0)
{-# LINE 71 "System/Posix/Fcntl.hsc" #-}
packAdvice AdviceRandom = (1)
{-# LINE 72 "System/Posix/Fcntl.hsc" #-}
packAdvice AdviceSequential = (2)
{-# LINE 73 "System/Posix/Fcntl.hsc" #-}
packAdvice AdviceWillNeed = (3)
{-# LINE 74 "System/Posix/Fcntl.hsc" #-}
packAdvice AdviceDontNeed = (4)
{-# LINE 75 "System/Posix/Fcntl.hsc" #-}
packAdvice AdviceNoReuse = (5)
{-# LINE 76 "System/Posix/Fcntl.hsc" #-}
{-# LINE 79 "System/Posix/Fcntl.hsc" #-}
fileAllocate :: Fd -> FileOffset -> FileOffset -> IO ()
{-# LINE 90 "System/Posix/Fcntl.hsc" #-}
fileAllocate fd off len = do
ret <- c_posix_fallocate (fromIntegral fd) (fromIntegral off) (fromIntegral len)
if ret == 0
then pure ()
else ioError (errnoToIOError "fileAllocate" (Errno ret) Nothing Nothing)
foreign import capi safe "fcntl.h posix_fallocate"
c_posix_fallocate :: CInt -> COff -> COff -> IO CInt
{-# LINE 104 "System/Posix/Fcntl.hsc" #-}