blob: dd5df7a785b96cca9a824825d423a938e7641b69 [file] [log] [blame] [raw]
#include <errno.h>
static int errno_private = 0;
#if 0
struct errentry {
unsigned long int ntstatus;
int errno;
};
static struct errentry errtable[] = {
{ 0x00000000L, 0 },
{ 0x00000102L, ETIME }
};
int ntstatus_to_errno(long int ntstatus) {
int i;
for(i = 0; i < (sizeof errtable / sizeof *errtable); i++) if(ntstatus == errtable.ntstatus) return errno_private = errtable.errno;
return errno_private = ntstatus_to_errno_other(ntstatus);
}
#else
static int ntstatus_to_errno_other(long int ntstatus) {
if(ntstatus <= 0xC0000131L && ntstatus >= 0xC000012EL) return ENOEXEC;
if(ntstatus <= 0xC00000FAL && ntstatus >= 0xC00000EFL) return EINVAL;
if(ntstatus <= 0xC0000403L && ntstatus >= 0xC0000401L) return EDQUOT;
if(ntstatus <= 0xC0000079L && ntstatus >= 0xC0000076L) return EINVAL;
if(ntstatus <= 0xC0000070L && ntstatus >= 0xC000006DL) return EACCES;
if(ntstatus <= 0xC0000062L && ntstatus >= 0xC000005EL) return EINVAL;
if(ntstatus <= 0xC0000018L && ntstatus >= 0xC000001BL) return EFAULT;
if(ntstatus <= 0x80000015L && ntstatus >= 0x80000013L) return EINVAL;
if(ntstatus <= 0x000000BFL && ntstatus >= 0x00000080L) return EOWNERDEAD;
if(ntstatus >= 0L) return 0;
// 0b__??0000________________________. ntstatus
// 0b1000__??________________________. errno
// sign
return 0x80000000 | ((ntstatus >> 4) & 0x0f000000) | (ntstatus & 0xffffff);
}
int ntstatus_to_errno(long int ntstatus) {
switch(ntstatus){
case 0x00000000L:
case 0xC0000011L:
case 0xFFFFFFFFL: return errno_private = 0;
case 0x00000102L: return errno_private = ETIME;
case 0x00000104L:
case 0x00000118L:
case 0x8000002DL: return errno_private = ENOLINK;
case 0x00000107L: return errno_private = ENOMSG;
case 0x0000010DL:
case 0xC0000007L:
case 0xC0000031L:
case 0xC0000044L:
case 0xC000012CL:
case 0xC00002E7L:
case 0xC0000410L:
case 0xC0000802L: return errno_private = EDQUOT;
case 0x0000010EL: return errno_private = ECONNABORTED;
case 0x00000114L: return errno_private = EHWPOISON;
case 0x00000119L:
case 0x80000011L:
case 0xC0000016L:
case 0xC000009AL:
case 0xC00000AEL:
case 0xC00000BFL: return errno_private = EBUSY;
case 0x40000003L:
case 0x4000000EL:
case 0x40000023L:
case 0xC000007BL:
case 0xC000011BL:
case 0xC0000139L: return errno_private = ENOEXEC;
case 0x4000001BL:
case 0x40190035L:
case 0xC00000FCL: return errno_private = EALREADY;
case 0x401E000AL:
case 0x80000001L:
case 0x80000005L:
case 0x801C0001L:
case 0xC0000023L:
case 0xC00000A1L:
case 0xC00000C6L:
case 0xC00000C7L: return errno_private = ENOBUFS;
case 0x401E034BL:
case 0x401E034CL:
case 0xC0000008L:
case 0xC0000042L:
case 0xC000011AL: return errno_private = EBADR;
case 0x401E042FL:
case 0x8000000FL:
case 0xC000000EL:
case 0xC00000C0L: return errno_private = ENODEV;
case 0x80000017L: return errno_private = EMSGSIZE;
case 0x80000025L:
case 0x80130004L:
case 0xC0000037L:
case 0xC000013BL:
case 0xC000013CL: return errno_private = ENOTCONN;
case 0x80000288L: return errno_private = EUCLEAN;
case 0x80130003L: return errno_private = EISCONN;
case 0x80190029L:
case 0xC0000089L:
case 0xC0000100L:
case 0xC0000109L: return errno_private = ENODATA;
case 0x80190031L:
case 0xC0000022L:
case 0xC0000038L:
case 0xC0000043L:
case 0xC0000046L:
case 0xC0000054L:
case 0xC000006AL:
case 0xC0000072L:
case 0xC00000CAL:
case 0xC00000EEL:
case 0xC0000107L:
case 0xC0000108L:
case 0xC0000137L: return errno_private = EACCES;
case 0x80210001L:
case 0xC0000006L:
case 0xC0000020L:
case 0xC000002BL:
case 0xC0000032L:
case 0xC000003EL:
case 0xC000009CL:
case 0xC00000B5L:
case 0xC00000C2L:
case 0xC00000E4L:
case 0xC00000E9L:
case 0xC0000102L: return errno_private = EIO;
case 0xC0000002L:
case 0xC000004FL:
case 0xC00000BBL: return errno_private = ENOSYS;
case 0xC0000003L:
case 0xC000000DL:
case 0xC000001CL:
case 0xC000001FL:
case 0xC0000024L:
case 0xC0000030L:
case 0xC0000033L:
case 0xC000004CL:
case 0xC0000050L:
case 0xC0000051L:
case 0xC000005AL:
case 0xC000005BL:
case 0xC000006BL:
case 0xC000006CL:
case 0xC000007CL:
case 0xC000007EL:
case 0xC0000084L:
case 0xC0000086L:
case 0xC00000A8L:
case 0xC00000B9L:
case 0xC00000E7L:
case 0xC000010BL:
case 0xC0000118L:
case 0xC0000119L:
case 0xC000011EL:
case 0xC0000122L:
case 0xC0000141L: return errno_private = EINVAL;
case 0xC0000005L:
case 0xC0000009L:
case 0xC000000AL:
case 0xC000001DL:
case 0xC0000025L:
case 0xC000002CL:
case 0xC000007AL:
case 0xC000009FL:
case 0xC00000A0L:
case 0xC00000FDL: return errno_private = EFAULT;
case 0xC000000FL:
case 0xC0000034L:
case 0xC000003AL:
case 0xC00000CCL:
case 0xC0000135L: return errno_private = ENOENT;
case 0xC0000010L:
case 0xC0000057L:
case 0xC0000069L:
case 0xC00000EDL: return errno_private = EPERM;
case 0xC0000012L:
case 0xC0000014L: return errno_private = EMEDIUMTYPE;
case 0xC0000013L: return errno_private = ENOMEDIUM;
case 0xC0000017L:
case 0xC000012DL: return errno_private = ENOMEM;
case 0xC0000021L: return errno_private = EADDRINUSE;
case 0xC0000035L: return errno_private = EEXIST;
case 0xC0000039L:
case 0xC000003BL:
case 0xC0000103L: return errno_private = ENOTDIR;
case 0xC000003CL:
case 0xC0000091L:
case 0xC0000095L: return errno_private = EOVERFLOW;
case 0xC0000041L:
case 0xC00000BCL: return errno_private = ECONNREFUSED;
case 0xC000007FL: return errno_private = ENOSPC;
case 0xC0000056L:
case 0xC0000467L: return errno_private = ETXTBSY;
case 0xC000008DL: return errno_private = EDOM;
case 0xC0000098L:
case 0xC00000ACL:
case 0xC00000AFL:
case 0xC00000B1L:
case 0xC00000B6L:
case 0xC0000128L:
case 0xC0000140L: return errno_private = EBADFD;
case 0xC000009DL: return errno_private = ENXIO;
case 0xC00000A2L: return errno_private = EROFS;
case 0xC00000A3L: return errno_private = ENOMEDIUM;
case 0xC00000A9L: return errno_private = EMEDIUMTYPE;
case 0xC00000ABL:
case 0xC000011FL: return errno_private = EMFILE;
case 0xC00000ADL:
case 0xC00000B0L:
case 0xC000014BL: return errno_private = EPIPE;
case 0xC00000BAL: return errno_private = EISDIR;
case 0xC00000BDL:
case 0xC00000E0L: return errno_private = ENOTUNIQ;
case 0xC00000BEL: return errno_private = ENETUNREACH;
case 0xC00000C5L:
case 0xC00000D2L: return errno_private = EREMOTEIO;
case 0xC00000C8L:
case 0xC0000120L: return errno_private = ECANCELED;
case 0xC00000CEL:
case 0xC00000D0L: return errno_private = EUSERS;
case 0xC00000CFL:
case 0xC00000D1L:
case 0xC00000D8L:
case 0xC00000D9L: return errno_private = EAGAIN;
case 0xC00000D3L: return errno_private = ENFILE;
case 0xC00000D4L: return errno_private = EXDEV;
case 0xC00000D6L:
case 0xC000013FL: return errno_private = ETIMEDOUT;
case 0xC0000101L: return errno_private = ENOTEMPTY;
case 0xC0000106L: return errno_private = ENAMETOOLONG;
case 0xC0000138L: return errno_private = ELIBBAD;
case 0xC000013EL: return errno_private = EPROTO;
}
return errno_private = ntstatus_to_errno_other(ntstatus);
}
#endif
int *_errno() {
return &errno_private;
}