X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FHandle.hs;h=37d78e6427dc54735d2d36c953ef79018d450db4;hb=cc4dd66d902a438d614f3031c89c7a5d5a555528;hp=762083c055fe4f0b478c8e40c82030254914cbbe;hpb=0da1e5c413f7cf3e4d9428fe657019a61e7eb0f5;p=ghc-base.git diff --git a/GHC/Handle.hs b/GHC/Handle.hs index 762083c..37d78e6 100644 --- a/GHC/Handle.hs +++ b/GHC/Handle.hs @@ -35,7 +35,7 @@ module GHC.Handle ( ioe_closedHandle, ioe_EOF, ioe_notReadable, ioe_notWritable, stdin, stdout, stderr, - IOMode(..), openFile, openBinaryFile, openTempFile, openBinaryTempFile, fdToHandle', fdToHandle, + IOMode(..), openFile, openBinaryFile, fdToHandle', fdToHandle, hFileSize, hSetFileSize, hIsEOF, isEOF, hLookAhead, hSetBuffering, hSetBinaryMode, hFlush, hDuplicate, hDuplicateTo, @@ -376,15 +376,9 @@ newEmptyBuffer b state size allocateBuffer :: Int -> BufferState -> IO Buffer allocateBuffer sz@(I# size) state = IO $ \s -> -#ifdef mingw32_HOST_OS - -- To implement asynchronous I/O under Win32, we have to pass - -- buffer references to external threads that handles the - -- filling/emptying of their contents. Hence, the buffer cannot - -- be moved around by the GC. + -- We sometimes need to pass the address of this buffer to + -- a "safe" foreign call, hence it must be immovable. case newPinnedByteArray# size s of { (# s, b #) -> -#else - case newByteArray# size s of { (# s, b #) -> -#endif (# s, newEmptyBuffer b state sz #) } writeCharIntoBuffer :: RawBuffer -> Int -> Char -> IO Int @@ -903,58 +897,6 @@ openFile' filepath mode binary = return h --- | The function creates a temporary file in ReadWrite mode. --- The created file isn\'t deleted automatically, so you need to delete it manually. -openTempFile :: FilePath -- ^ Directory in which to create the file - -> String -- ^ File name template. If the template is \"foo.ext\" then - -- the create file will be \"fooXXX.ext\" where XXX is some - -- random number. - -> IO (FilePath, Handle) -openTempFile tmp_dir template = openTempFile' "openTempFile" tmp_dir template dEFAULT_OPEN_IN_BINARY_MODE - --- | Like 'openTempFile', but opens the file in binary mode. See 'openBinaryFile' for more comments. -openBinaryTempFile :: FilePath -> String -> IO (FilePath, Handle) -openBinaryTempFile tmp_dir template = openTempFile' "openBinaryTempFile" tmp_dir template True - -openTempFile' :: String -> FilePath -> String -> Bool -> IO (FilePath, Handle) -openTempFile' loc tmp_dir template binary = do - pid <- c_getpid - findTempName pid - where - (prefix,suffix) = break (=='.') template - - oflags1 = rw_flags .|. o_EXCL - - binary_flags - | binary = o_BINARY - | otherwise = 0 - - oflags = oflags1 .|. binary_flags - - findTempName x = do - fd <- withCString filepath $ \ f -> - c_open f oflags 0o666 - if fd < 0 - then do - errno <- getErrno - if errno == eEXIST - then findTempName (x+1) - else ioError (errnoToIOError loc errno Nothing (Just tmp_dir)) - else do - h <- fdToHandle' fd Nothing False filepath ReadWriteMode True - `catchException` \e -> do c_close fd; throw e - return (filepath, h) - where - filename = prefix ++ show x ++ suffix - filepath = tmp_dir ++ [pathSeparator] ++ filename - -pathSeparator :: Char -#ifdef mingw32_HOST_OS -pathSeparator = '\\' -#else -pathSeparator = '/' -#endif - std_flags = o_NONBLOCK .|. o_NOCTTY output_flags = std_flags .|. o_CREAT read_flags = std_flags .|. o_RDONLY