| #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(unsigned 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(unsigned long int ntstatus) { |
| 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; |
| } |
| |
| int ntstatus_to_errno(unsigned long int ntstatus) { |
| switch(ntstatus){ |
| case 0x00000000L: return errno_private = 0; |
| case 0x00000102L: return errno_private = ETIME; |
| case 0x00000104L: |
| case 0x00000118L: 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 0xC0000056L: return errno_private = EBUSY; |
| |
| case 0x40000003L: |
| case 0x4000000EL: |
| case 0x40000023L: |
| case 0xC000007BL: |
| case 0xC0000089L: return errno_private = ENOEXEC; |
| case 0x4000001BL: |
| case 0x40190035L: return errno_private = EALREADY; |
| case 0x401E000AL: |
| case 0x80000001L: |
| case 0x80000005L: |
| case 0x801C0001L: |
| case 0xC0000023L: return errno_private = ENOBUFS; |
| case 0x401E034BL: |
| case 0x401E034CL: |
| case 0xC0000008L: |
| case 0xC0000042L: return errno_private = EBADR; |
| case 0x401E042FL: |
| case 0x8000000FL: |
| case 0xC000000EL: return errno_private = ENODEV; |
| case 0x80000017L: return errno_private = EMSGSIZE; |
| case 0x80000025L: |
| case 0x80130004L: |
| case 0xC0000037L: return errno_private = ENOTCONN; |
| case 0x80000288L: return errno_private = EUCLEAN; |
| case 0x80130003L: return errno_private = EISCONN; |
| case 0x80190031L: |
| case 0xC0000022L: |
| case 0xC0000038L: |
| case 0xC0000043L: |
| case 0xC0000046L: |
| case 0xC0000054L: |
| case 0xC000006AL: |
| case 0xC0000072L: return errno_private = EACCES; |
| case 0x80210001L: |
| case 0xC0000006L: |
| case 0xC0000020L: |
| case 0xC000002BL: |
| case 0xC0000032L: |
| case 0xC000003EL: return errno_private = EIO; |
| case 0xC0000002L: |
| case 0xC000004FL: return errno_private = ENOSYS; |
| case 0xC0000003L: |
| case 0xC000000DL: |
| case 0xC000001CL: |
| case 0xC000001FL: |
| 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: return errno_private = EINVAL; |
| case 0xC0000005L: |
| case 0xC0000009L: |
| case 0xC000000AL: |
| case 0xC000001DL: |
| case 0xC0000025L: |
| case 0xC000002CL: |
| case 0xC000007AL: return errno_private = EFAULT; |
| case 0xC000000FL: |
| case 0xC0000034L: |
| case 0xC000003AL: return errno_private = ENOENT; |
| case 0xC0000010L: |
| case 0xC0000057L: |
| case 0xC0000069L: return errno_private = EPERM; |
| case 0xC0000012L: |
| case 0xC0000014L: return errno_private = EMEDIUMTYPE; |
| case 0xC0000013L: return errno_private = ENOMEDIUM; |
| case 0xC0000017L: return errno_private = ENOMEM; |
| case 0xC0000021L: return errno_private = EADDRINUSE; |
| case 0xC0000035L: return errno_private = EEXIST; |
| case 0xC0000039L: |
| case 0xC000003BL: return errno_private = ENOTDIR; |
| case 0xC0000467L: return errno_private = ETXTBSY; |
| //case 0x00000080L: return errno_private = EOWNERDEAD; |
| //default: return errno_private = EINVAL; |
| //default: return errno_private = -1; |
| } |
| return errno_private = ntstatus_to_errno_other(ntstatus); |
| } |
| |
| #endif |
| |
| int *_errno() { |
| return &errno_private; |
| } |