Skip to content

Commit 1204e8b

Browse files
committed
Fix support for GHC =< 8.10
1 parent 2a37e10 commit 1204e8b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

windows/System/File/Platform.hsc

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ writeShareMode =
102102
Win32.fILE_SHARE_DELETE .|.
103103
Win32.fILE_SHARE_READ
104104

105-
-- | Open an existing file and return the 'Handle'.
105+
-- | Open an existing file and return the 'Handle'.
106106
openExistingFile :: WindowsPath -> IOMode -> IO Handle
107107
openExistingFile fp iomode = bracketOnError
108108
(WS.createFile
@@ -168,6 +168,7 @@ findTempName (prefix, suffix) loc tmp_dir mode = go
168168
#endif
169169
withTString label $ \c_template ->
170170
withTString suffix $ \c_suffix ->
171+
#if MIN_VERSION_base(4, 15, 0)
171172
with nullPtr $ \c_ptr -> do
172173
res <- c_createUUIDTempFileErrNo c_tmp_dir c_template c_suffix c_ptr
173174
if not res
@@ -178,13 +179,31 @@ findTempName (prefix, suffix) loc tmp_dir mode = go
178179
free c_p
179180
let flags = fromIntegral mode .&. o_EXCL
180181
handleResultsWinIO filename (flags == o_EXCL)
182+
#else
183+
-- NOTE: revisit this when new I/O manager in place and use a UUID
184+
-- based one when we are no longer MAX_PATH bound.
185+
allocaBytes (sizeOf (undefined :: CWchar) * 260) $ \c_str -> do
186+
res <- c_getTempFileNameErrorNo c_tmp_dir c_template c_suffix 0
187+
c_str
188+
if not res
189+
then do errno <- getErrno
190+
ioError (errnoToIOError loc errno Nothing (Just $ lenientDecode tmp_dir))
191+
else do filename <- peekTString c_str
192+
let flags = fromIntegral mode .&. o_EXCL
193+
handleResultsWinIO filename (flags == o_EXCL)
194+
#endif
181195

182196
handleResultsWinIO filename excl = do
183197
h <- (if excl then openExistingFile else openFile) filename ReadWriteMode
184198
return (filename, h)
185199

200+
#if MIN_VERSION_base(4, 15, 0)
186201
foreign import ccall "__createUUIDTempFileErrNo" c_createUUIDTempFileErrNo
187202
:: CWString -> CWString -> CWString -> Ptr CWString -> IO Bool
203+
#else
204+
foreign import ccall "getTempFileNameErrorNo" c_getTempFileNameErrorNo
205+
:: CWString -> CWString -> CWString -> CUInt -> Ptr CWchar -> IO Bool
206+
#endif
188207

189208

190209

0 commit comments

Comments
 (0)