@@ -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'.
106106openExistingFile :: WindowsPath -> IOMode -> IO Handle
107107openExistingFile 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)
186201foreign 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