2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
12 /* The errno_xlat_table contains the errno-to-Win32 error
13 * mapping. Since this is a single table, it can't easily
14 * take into account function-specific differences, so there
15 * will probably be quite a few points where we don't exactly
16 * match what NT would return. Then again, neither does
24 /* The table looks pretty ugly due to the preprocessor stuff,
25 * but I honestly have no idea how many of these values are
26 * portable. I'm not even sure how many of them are even
29 static ERRNO_XLAT_TABLE errno_xlat_table
[] = {
31 { EPERM
, ERROR_ACCESS_DENIED
},
34 { ENOENT
, ERROR_FILE_NOT_FOUND
},
37 { ESRCH
, ERROR_INVALID_PARAMETER
},
40 { EIO
, ERROR_IO_DEVICE
},
43 { ENOEXEC
, ERROR_BAD_FORMAT
},
46 { EBADF
, ERROR_INVALID_HANDLE
},
49 { ENOMEM
, ERROR_OUTOFMEMORY
},
52 { EACCES
, ERROR_ACCESS_DENIED
},
55 { EBUSY
, ERROR_BUSY
},
58 { EEXIST
, ERROR_FILE_EXISTS
},
61 { ENODEV
, ERROR_BAD_DEVICE
},
64 { EINVAL
, ERROR_INVALID_PARAMETER
},
67 { EMFILE
, ERROR_TOO_MANY_OPEN_FILES
},
70 { ETXTBSY
, ERROR_BUSY
, },
73 { ENOSPC
, ERROR_DISK_FULL
},
76 { ESPIPE
, ERROR_SEEK_ON_DEVICE
},
79 { EPIPE
, ERROR_BROKEN_PIPE
},
82 { EDEADLK
, ERROR_POSSIBLE_DEADLOCK
},
84 #if defined(ENAMETOOLONG)
85 { ENAMETOOLONG
, ERROR_FILENAME_EXCED_RANGE
},
87 #if defined(ENOTEMPTY)
88 { ENOTEMPTY
, ERROR_DIR_NOT_EMPTY
},
93 DWORD
ErrnoToLastError(int errno_num
)
95 DWORD rc
= ERROR_UNKNOWN
;
98 while(errno_xlat_table
[i
].err
!= -1)
100 if(errno_xlat_table
[i
].err
== errno_num
)
102 rc
= errno_xlat_table
[i
].win32err
;
111 int LastErrorToErrno(DWORD lasterror
)
113 int rc
= 0; /* no error */
116 while(errno_xlat_table
[i
].err
!= -1)
118 if(errno_xlat_table
[i
].win32err
== lasterror
)
120 rc
= errno_xlat_table
[i
].err
;