ghcjs-stack/special/Win32/tests/lasterror.hs
Marcin Tolysz bc87678a71 init
2016-01-30 23:49:30 +00:00

19 lines
508 B
Haskell

{-# LANGUAGE ForeignFunctionInterface #-}
-- Test that the Win32 error code from getLastError is thread-local.
import System.Win32
import Control.Monad
import Control.Concurrent
main = do
setLastError 42
r <- getLastError
when (r /= 42) $ fail ("wrong: " ++ show r)
m <- newEmptyMVar
forkIO $ do setLastError 43; putMVar m ()
takeMVar m
r <- getLastError
when (r /= 42) $ fail ("wrong: " ++ show r)
foreign import stdcall unsafe "windows.h SetLastError"
setLastError :: ErrCode -> IO ()