|
1 | 1 | module Streamly.Internal.FileSystem.Windows.File |
2 | | - ( openExistingFile |
3 | | - , openFile |
4 | | - , openExistingFileWithCloseOnExec |
5 | | - , openFileWithCloseOnExec |
| 2 | + ( -- openExistingFile |
| 3 | + -- openFile |
| 4 | + createFile |
| 5 | + -- , openExistingFileWithCloseOnExec |
| 6 | + -- , openFileWithCloseOnExec |
6 | 7 | ) where |
7 | 8 |
|
8 | 9 | ------------------------------------------------------------------------------- |
@@ -43,7 +44,6 @@ import qualified Streamly.Internal.Data.Array as Array |
43 | 44 | foreign import WINDOWS_CCONV unsafe "windows.h CreateFileW" |
44 | 45 | c_CreateFile :: LPCTSTR -> AccessMode -> ShareMode -> LPSECURITY_ATTRIBUTES -> CreateMode -> FileAttributeOrFlag -> HANDLE -> IO HANDLE |
45 | 46 |
|
46 | | - |
47 | 47 | -- | like failIf, but retried on sharing violations. This is necessary for many |
48 | 48 | -- file operations; see |
49 | 49 | -- https://www.betaarchive.com/wiki/index.php/Microsoft_KB_Archive/316609 |
@@ -81,6 +81,30 @@ createFile name access share mb_attr mode flag mb_h = |
81 | 81 | failIfWithRetry (==iNVALID_HANDLE_VALUE) (unwords ["CreateFile",show name]) $ |
82 | 82 | c_CreateFile c_name access share (maybePtr mb_attr) mode flag (maybePtr mb_h) |
83 | 83 |
|
| 84 | +{- |
| 85 | +maxShareMode :: Win32.ShareMode |
| 86 | +maxShareMode = |
| 87 | + Win32.fILE_SHARE_DELETE .|. |
| 88 | + Win32.fILE_SHARE_READ .|. |
| 89 | + Win32.fILE_SHARE_WRITE |
| 90 | +
|
| 91 | +writeShareMode :: Win32.ShareMode |
| 92 | +writeShareMode = |
| 93 | + Win32.fILE_SHARE_DELETE .|. |
| 94 | + Win32.fILE_SHARE_READ |
| 95 | +
|
| 96 | +toHandle :: WindowsPath -> IOMode -> Win32.HANDLE -> IO Handle |
| 97 | +#if defined(__IO_MANAGER_WINIO__) |
| 98 | +toHandle _ iomode h = (`onException` Win32.closeHandle h) $ do |
| 99 | + when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END |
| 100 | + Win32.hANDLEToHandle h |
| 101 | +#else |
| 102 | +toHandle fp iomode h = (`onException` Win32.closeHandle h) $ do |
| 103 | + when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END |
| 104 | + fd <- _open_osfhandle (fromIntegral (ptrToIntPtr h)) (#const _O_BINARY) |
| 105 | + fdToHandle' fd Nothing False (Path.toString fp) iomode True |
| 106 | +#endif |
| 107 | +
|
84 | 108 | -- | Open a file and return the 'Handle'. |
85 | 109 | openFile :: WindowsPath -> IOMode -> IO Handle |
86 | 110 | openFile fp iomode = bracketOnError |
@@ -121,17 +145,6 @@ openFile fp iomode = bracketOnError |
121 | 145 | ReadWriteMode -> maxShareMode |
122 | 146 |
|
123 | 147 |
|
124 | | -maxShareMode :: Win32.ShareMode |
125 | | -maxShareMode = |
126 | | - Win32.fILE_SHARE_DELETE .|. |
127 | | - Win32.fILE_SHARE_READ .|. |
128 | | - Win32.fILE_SHARE_WRITE |
129 | | - |
130 | | -writeShareMode :: Win32.ShareMode |
131 | | -writeShareMode = |
132 | | - Win32.fILE_SHARE_DELETE .|. |
133 | | - Win32.fILE_SHARE_READ |
134 | | - |
135 | 148 | -- | Open an existing file and return the 'Handle'. |
136 | 149 | openExistingFile :: WindowsPath -> IOMode -> IO Handle |
137 | 150 | openExistingFile fp iomode = bracketOnError |
@@ -182,14 +195,4 @@ openFileWithCloseOnExec = openFile |
182 | 195 | openExistingFileWithCloseOnExec :: WindowsPath -> IOMode -> IO Handle |
183 | 196 | openExistingFileWithCloseOnExec = openExistingFile |
184 | 197 |
|
185 | | -toHandle :: WindowsPath -> IOMode -> Win32.HANDLE -> IO Handle |
186 | | -#if defined(__IO_MANAGER_WINIO__) |
187 | | -toHandle _ iomode h = (`onException` Win32.closeHandle h) $ do |
188 | | - when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END |
189 | | - Win32.hANDLEToHandle h |
190 | | -#else |
191 | | -toHandle fp iomode h = (`onException` Win32.closeHandle h) $ do |
192 | | - when (iomode == AppendMode ) $ void $ Win32.setFilePointerEx h 0 Win32.fILE_END |
193 | | - fd <- _open_osfhandle (fromIntegral (ptrToIntPtr h)) (#const _O_BINARY) |
194 | | - fdToHandle' fd Nothing False (Path.toString fp) iomode True |
195 | | -#endif |
| 198 | +-} |
0 commit comments