summaryrefslogtreecommitdiff
path: root/src/unix/Erebos/Storage
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2024-06-29 16:39:57 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2024-06-29 17:58:42 +0200
commit414f810c7c1d9aedeaa45e0998537395e7f4a907 (patch)
treed01b84764ecc32843da60ef6bcb5a311e3ef1be7 /src/unix/Erebos/Storage
parent15f7d82c37cb1b0e12a1eade91e0db2e132d4c60 (diff)
Move platform-specific code to separate directory
Diffstat (limited to 'src/unix/Erebos/Storage')
-rw-r--r--src/unix/Erebos/Storage/Platform.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/unix/Erebos/Storage/Platform.hs b/src/unix/Erebos/Storage/Platform.hs
new file mode 100644
index 0000000..2198f61
--- /dev/null
+++ b/src/unix/Erebos/Storage/Platform.hs
@@ -0,0 +1,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