- License: BSD-2-clause
-}
-{-# LANGUAGE OverloadedStrings, CPP #-}
+{-# LANGUAGE OverloadedStrings #-}
module Utility.LockFile.Windows (
lockShared,
openLock :: ShareMode -> LockFile -> IO (Maybe LockHandle)
openLock sharemode f = do
f' <- convertToWindowsNativeNamespace f
-#if MIN_VERSION_Win32(2,13,4)
r <- tryNonAsync $ createFile_NoRetry f' gENERIC_READ sharemode
security_attributes oPEN_ALWAYS fILE_ATTRIBUTE_NORMAL
(maybePtr Nothing)
return $ case r of
Left _ -> Nothing
Right h -> Just h
-#else
- h <- withTString (fromRawFilePath f') $ \c_f ->
- c_CreateFile c_f gENERIC_READ sharemode security_attributes
- oPEN_ALWAYS fILE_ATTRIBUTE_NORMAL (maybePtr Nothing)
- return $ if h == iNVALID_HANDLE_VALUE
- then Nothing
- else Just h
-#endif
where
security_attributes = maybePtr Nothing