summaryrefslogtreecommitdiff
path: root/libraries/base/cbits
diff options
context:
space:
mode:
authorJoey Adams <joeyadams3.14159@gmail.com>2012-11-12 21:48:08 -0500
committerJoey Adams <joeyadams3.14159@gmail.com>2012-11-17 19:30:23 -0500
commita651570ea61da84af2587d346e11fc336150a586 (patch)
tree05bf87fccbaf2776275afb11e85683e83f8632cb /libraries/base/cbits
parent1e41f1ba595fdf9e76c8c770428573f9675f8cab (diff)
downloadhaskell-a651570ea61da84af2587d346e11fc336150a586.tar.gz
GHC.Windows: more error support (guards, system error strings)
This changes the output of throwGetLastError to include the system error message, rather than the message of our fictitious errno. It also adds several definitions to GHC.Windows, mostly from the Win32 package. The exceptions are: * getErrorMessage: returns a String, unlike in System.Win32.Types, where it returns an LPWSTR. * errCodeToIOError: new * c_maperrno_func: new
Diffstat (limited to 'libraries/base/cbits')
-rw-r--r--libraries/base/cbits/Win32Utils.c69
1 files changed, 42 insertions, 27 deletions
diff --git a/libraries/base/cbits/Win32Utils.c b/libraries/base/cbits/Win32Utils.c
index ecd54f32c2..7038cbf48e 100644
--- a/libraries/base/cbits/Win32Utils.c
+++ b/libraries/base/cbits/Win32Utils.c
@@ -80,34 +80,49 @@ static struct errentry errtable[] = {
#define MIN_EACCES_RANGE ERROR_WRITE_PROTECT
#define MAX_EACCES_RANGE ERROR_SHARING_BUFFER_EXCEEDED
-void maperrno (void)
+void maperrno(void)
{
- int i;
- DWORD dwErrorCode;
-
- dwErrorCode = GetLastError();
-
- /* check the table for the OS error code */
- for (i = 0; i < ERRTABLESIZE; ++i)
- {
- if (dwErrorCode == errtable[i].oscode)
- {
- errno = errtable[i].errnocode;
- return;
- }
- }
-
- /* The error code wasn't in the table. We check for a range of */
- /* EACCES errors or exec failure errors (ENOEXEC). Otherwise */
- /* EINVAL is returned. */
-
- if (dwErrorCode >= MIN_EACCES_RANGE && dwErrorCode <= MAX_EACCES_RANGE)
- errno = EACCES;
- else
- if (dwErrorCode >= MIN_EXEC_ERROR && dwErrorCode <= MAX_EXEC_ERROR)
- errno = ENOEXEC;
- else
- errno = EINVAL;
+ errno = maperrno_func(GetLastError());
+}
+
+int maperrno_func(DWORD dwErrorCode)
+{
+ int i;
+
+ /* check the table for the OS error code */
+ for (i = 0; i < ERRTABLESIZE; ++i)
+ if (dwErrorCode == errtable[i].oscode)
+ return errtable[i].errnocode;
+
+ /* The error code wasn't in the table. We check for a range of */
+ /* EACCES errors or exec failure errors (ENOEXEC). Otherwise */
+ /* EINVAL is returned. */
+
+ if (dwErrorCode >= MIN_EACCES_RANGE && dwErrorCode <= MAX_EACCES_RANGE)
+ return EACCES;
+ else if (dwErrorCode >= MIN_EXEC_ERROR && dwErrorCode <= MAX_EXEC_ERROR)
+ return ENOEXEC;
+ else
+ return EINVAL;
+}
+
+LPWSTR base_getErrorMessage(DWORD err)
+{
+ LPWSTR what;
+ DWORD res;
+
+ res = FormatMessageW(
+ (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER),
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
+ (LPWSTR) &what,
+ 0,
+ NULL
+ );
+ if (res == 0)
+ return NULL;
+ return what;
}
int get_unique_file_info(int fd, HsWord64 *dev, HsWord64 *ino)