base-4.8.0.0: Basic libraries

Copyright | (c) The University of Glasgow, 2009
License | see libraries/base/LICENSE
Maintainer | libraries@haskell.org
Stability | internal
Portability | non-portable
Safe Haskell | Trustworthy
Language | Haskell2010

GHC.Windows

Contents

- Types
- Constants
- System errors
  - Guards for system calls that might fail
  - Mapping system errors to errno

Description

Windows functionality used by several modules.

ToDo: this just duplicates part of System.Win32.Types, which isn't available yet. We should move some Win32 functionality down here, maybe as part of the grand reorganisation of the base package...

Synopsis

- type BOOL = Bool
- type LPBOOL = Ptr BOOL
- type BYTE = Word8
- type DWORD = Word32
- type UINT = Word32
- type ErrCode = DWORD
- type HANDLE = Ptr ()
- type LPWSTR = Ptr CWchar
- type LPTSTR = LPWSTR
- iNFINITE :: DWORD
- iNVALID_HANDLE_VALUE :: HANDLE
- throwGetLastError :: String -> IO a
- failWith :: String -> ErrCode -> IO a
- getLastError :: IO ErrCode
- getErrorMessage :: ErrCode -> IO String
- errCodeToIOError :: String -> ErrCode -> IO IOError
- failIf :: (a -> Bool) -> String -> IO a -> IO a
- failIf_ :: (a -> Bool) -> String -> IO a -> IO ()
- failIfNull :: String -> IO (Ptr a) -> IO (Ptr a)
- failIfZero :: (Eq a, Num a) => String -> IO a -> IO a
- failIfFalse_ :: String -> IO Bool -> IO ()
- failUnlessSuccess :: String -> IO ErrCode -> IO ()
- failUnlessSuccessOr :: ErrCode -> String -> IO ErrCode -> IO Bool
- c_maperrno :: IO ()
- c_maperrno_func :: ErrCode -> Errno

# Types

type BOOL = Bool

type LPBOOL = Ptr BOOL

type BYTE = Word8

type DWORD = Word32

type UINT = Word32

type ErrCode = DWORD

type HANDLE = Ptr ()

type LPWSTR = Ptr CWchar

type LPTSTR = LPWSTR

Be careful with this. LPTSTR can mean either WCHAR* or CHAR*, depending on whether the UNICODE macro is defined in the corresponding C code. Consider using LPWSTR instead.

# Constants

iNFINITE :: DWORD

iNVALID_HANDLE_VALUE :: HANDLE

# System errors

throwGetLastError :: String -> IO a

Get the last system error, and throw it as an `IOError` exception.

failWith :: String -> ErrCode -> IO a

Convert a Windows error code to an exception, then throw it.

getLastError :: IO ErrCode

Get the last system error produced in the current thread.

getErrorMessage :: ErrCode -> IO String

Get a string describing a Windows error code. This uses the `FormatMessage` system call.

errCodeToIOError :: String -> ErrCode -> IO IOError

Convert a Windows error code to an exception.

## Guards for system calls that might fail

failIf :: (a -> Bool) -> String -> IO a -> IO a

failIf_ :: (a -> Bool) -> String -> IO a -> IO ()

failIfNull :: String -> IO (Ptr a) -> IO (Ptr a)

failIfZero :: (Eq a, Num a) => String -> IO a -> IO a

failIfFalse_ :: String -> IO Bool -> IO ()

failUnlessSuccess :: String -> IO ErrCode -> IO ()

failUnlessSuccessOr :: ErrCode -> String -> IO ErrCode -> IO Bool

## Mapping system errors to errno

On Windows, `errno` is defined by msvcrt.dll for compatibility with other systems, and is distinct from the system error as returned by `GetLastError`.

c_maperrno :: IO ()

Map the last system error to an errno value, and assign it to `errno`.

c_maperrno_func :: ErrCode -> Errno

Pure function variant of `c_maperrno` that does not call `GetLastError` or modify `errno`.