summaryrefslogtreecommitdiff
path: root/src/unix/Erebos/Storage/Platform.hs
blob: 2198f6109e2685ae8dc40755bb7a895e459ed656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{-# LANGUAGE CPP #-}

module Erebos.Storage.Platform (
    createFileExclusive,
) where

import System.IO
import System.Posix.Files
import System.Posix.IO

createFileExclusive :: FilePath -> IO Handle
createFileExclusive path = fdToHandle =<< do
#if MIN_VERSION_unix(2,8,0)
    openFd path WriteOnly defaultFileFlags
        { creat = Just $ unionFileModes ownerReadMode ownerWriteMode
        , exclusive = True
        }
#else
    openFd path WriteOnly (Just $ unionFileModes ownerReadMode ownerWriteMode) (defaultFileFlags { exclusive = True })
#endif