| #include <errno.h> |
| |
| static int errno_private = 0; |
| |
| #if 0 |
| |
| struct errentry { |
| 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 errtable.errno; |
| return __ntstatus_to_errno_other(ntstatus); |
| } |
| |
| #else |
| |
| static int __ntstatus_to_errno_other(long int ntstatus) { |
| if(ntstatus <= 0xC0020025L && ntstatus >= 0xC0020022L) return EINVAL; |
| if(ntstatus <= 0xC0020008L && ntstatus >= 0xC0020006L) return EINVAL; |
| if(ntstatus <= 0xC0020003L && ntstatus >= 0xC0020001L) return EINVAL; |
| if(ntstatus <= 0xC0000403L && ntstatus >= 0xC0000401L) return EDQUOT; |
| if(ntstatus <= 0xC0000364L && ntstatus >= 0xC0000361L) return EACCES; |
| if(ntstatus <= 0xC000030BL && ntstatus >= 0xC0000305L) return EACCES; |
| if(ntstatus <= 0xC00002DCL && ntstatus >= 0xC00002D7L) return EPERM; |
| if(ntstatus <= 0xC000016BL && ntstatus >= 0xC0000166L) return EIO; |
| if(ntstatus <= 0xC0000163L && ntstatus >= 0xC0000161L) return EINVAL; |
| if(ntstatus <= 0xC0000131L && ntstatus >= 0xC000012EL) return ENOEXEC; |
| if(ntstatus <= 0xC00000FAL && ntstatus >= 0xC00000EFL) return EINVAL; |
| 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 0; |
| case 0x00000102L: return ETIME; |
| case 0x00000107L: return ENOMSG; |
| case 0x0000010DL: |
| case 0xC0000007L: |
| case 0xC0000031L: |
| case 0xC0000044L: |
| case 0xC000012CL: |
| case 0xC00002E7L: |
| case 0xC0000410L: |
| case 0xC0000802L: return EDQUOT; |
| case 0x0000010EL: |
| case 0xC000020FL: |
| case 0xC0000241L: return ECONNABORTED; |
| case 0x40000003L: |
| case 0x4000000EL: |
| case 0x40000023L: |
| case 0xC000007BL: |
| case 0xC000011BL: |
| case 0xC0000139L: |
| case 0xC000014CL: |
| case 0xC000015CL: |
| case 0xC0000359L: |
| case 0xC000035AL: |
| case 0xC0000424L: |
| case 0xC0000428L: |
| case 0xC00A0002L: |
| case 0xC00A002EL: return ENOEXEC; |
| case 0x4000001BL: |
| case 0x40190035L: |
| case 0xC00000FCL: return EALREADY; |
| case 0x401E000AL: |
| case 0x80000001L: |
| case 0x80000005L: |
| case 0x801C0001L: |
| case 0xC0000023L: |
| case 0xC00000A1L: |
| case 0xC00000C6L: |
| case 0xC00000C7L: |
| case 0xC0000231L: |
| case 0xC00A0007L: return ENOBUFS; |
| case 0x401E034BL: |
| case 0x401E034CL: |
| case 0xC0000008L: |
| case 0xC0000042L: |
| case 0xC000011AL: return EBADR; |
| case 0x401E042FL: |
| case 0x8000000FL: |
| case 0xC000000EL: |
| case 0xC00000C0L: |
| case 0xC00002B6L: |
| case 0xC0000452L: return ENODEV; |
| case 0x80000011L: |
| case 0xC0000016L: |
| case 0xC000009AL: |
| case 0xC00000AEL: |
| case 0xC00000BFL: |
| case 0xC0000175L: |
| case 0xC0000176L: |
| case 0xC00002A5L: |
| case 0xC00A0017L: return EBUSY; |
| case 0x80000017L: return EMSGSIZE; |
| case 0x80000025L: |
| case 0x80130004L: |
| case 0xC0000037L: |
| case 0xC000013BL: |
| case 0xC000013CL: |
| case 0xC000020CL: |
| case 0xC0000237L: return ENOTCONN; |
| case 0x8000002DL: return ENOLINK; |
| case 0x80000288L: return EUCLEAN; |
| case 0x80130003L: return EISCONN; |
| case 0x80190029L: |
| case 0xC0000089L: |
| case 0xC0000100L: |
| case 0xC0000109L: |
| case 0xC000015FL: |
| case 0xC0000204L: |
| case 0xC00002F8L: |
| case 0xC0030061L: return 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 0xC0000121L: |
| case 0xC0000137L: |
| case 0xC0000155L: |
| case 0xC000015AL: |
| case 0xC000015BL: |
| case 0xC000015DL: |
| case 0xC000017FL: |
| case 0xC0000193L: |
| case 0xC0000201L: |
| case 0xC0000247L: |
| case 0xC0000248L: |
| case 0xC0000293L: |
| case 0xC0000299L: |
| case 0xC00002C3L: |
| case 0xC00002C6L: |
| case 0xC0000372L: |
| case 0xC0000380L: |
| case 0xC0000382L: |
| case 0xC0000413L: |
| case 0xC0000414L: |
| case 0xC0000418L: |
| case 0xC0000905L: |
| case 0xC0020064L: |
| case 0xC00A0012L: |
| case 0xC00A002AL: |
| case 0xC00A002BL: return 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: |
| case 0xC000014DL: |
| case 0xC000016DL: |
| case 0xC0000172L: |
| case 0xC0000183L: |
| case 0xC0000185L: |
| case 0xC0000189L: |
| case 0xC0000222L: |
| case 0xC000026EL: |
| case 0xC0000387L: |
| case 0xC0000805L: |
| case 0xC000A082L: return EIO; |
| case 0xC0000002L: |
| case 0xC000004FL: |
| case 0xC00000BBL: |
| case 0xC00002F3L: |
| case 0xC0000429L: return 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: |
| case 0xC000014FL: |
| case 0xC0000173L: |
| case 0xC0000182L: |
| case 0xC0000206L: |
| case 0xC0000223L: |
| case 0xC00002A2L: |
| case 0xC00002D4L: |
| case 0xC00002F2L: |
| case 0xC00002FBL: |
| case 0xC0000369L: |
| case 0xC0000417L: |
| case 0xC0000446L: |
| case 0xC0000465L: |
| case 0xC0000500L: |
| case 0xC0000501L: |
| case 0xC0000716L: |
| case 0xC002000AL: |
| case 0xC0020019L: |
| case 0xC0020032L: |
| case 0xC0020034L: |
| case 0xC0020038L: |
| case 0xC0020039L: |
| case 0xC0020040L: |
| case 0xC0030004L: |
| case 0xC0030005L: |
| case 0xC0030007L: |
| case 0xC003000AL: |
| case 0xC003000CL: |
| case 0xC0030059L: |
| case 0xC00A0001L: |
| case 0xC00A0022L: |
| case 0xC00A0030L: return EINVAL; |
| case 0xC0000005L: |
| case 0xC0000009L: |
| case 0xC000000AL: |
| case 0xC000001DL: |
| case 0xC0000025L: |
| case 0xC000002CL: |
| case 0xC000007AL: |
| case 0xC000009FL: |
| case 0xC00000A0L: |
| case 0xC00000FDL: |
| case 0xC0000374L: |
| case 0xC0030009L: return EFAULT; |
| case 0xC000000FL: |
| case 0xC0000034L: |
| case 0xC000003AL: |
| case 0xC00000CCL: |
| case 0xC0000135L: |
| case 0xC0000225L: |
| case 0xC0000267L: |
| case 0xC0000280L: |
| case 0xC000029AL: |
| case 0xC002000BL: |
| case 0xC00A0003L: |
| case 0xC00A0008L: |
| case 0xC00A0015L: |
| case 0xC00A002FL: return ENOENT; |
| case 0xC0000010L: |
| case 0xC0000057L: |
| case 0xC0000069L: |
| case 0xC00000EDL: |
| case 0xC0000187L: |
| case 0xC0000235L: |
| case 0xC00002AEL: |
| case 0xC00002B3L: |
| case 0xC00002C7L: |
| case 0xC00002CDL: |
| case 0xC00002D0L: |
| case 0xC00002E9L: |
| case 0xC0000426L: |
| case 0xC0000715L: |
| case 0xC0020035L: |
| case 0xC0020041L: |
| case 0xC003005DL: |
| case 0xC00A0031L: return EPERM; |
| case 0xC0000012L: |
| case 0xC0000014L: return EMEDIUMTYPE; |
| case 0xC0000013L: |
| case 0xC0000178L: |
| case 0xC0000283L: return ENOMEDIUM; |
| case 0xC0000017L: |
| case 0xC000012DL: |
| case 0xC0000373L: return ENOMEM; |
| case 0xC0000021L: |
| case 0xC0000209L: |
| case 0xC000020AL: |
| case 0xC0000254L: |
| case 0xC0000255L: return EADDRINUSE; |
| case 0xC0000035L: |
| case 0xC00A0016L: return EEXIST; |
| case 0xC0000039L: |
| case 0xC000003BL: |
| case 0xC0000103L: return ENOTDIR; |
| case 0xC000003CL: |
| case 0xC0000095L: return EOVERFLOW; |
| case 0xC0000041L: |
| case 0xC00000BCL: |
| case 0xC0000236L: |
| case 0xC000023FL: return ECONNREFUSED; |
| case 0xC000007FL: |
| case 0xC0000177L: |
| case 0xC000017DL: |
| case 0xC0000188L: return ENOSPC; |
| case 0xC0000056L: |
| case 0xC0000433L: |
| case 0xC0000467L: return ETXTBSY; |
| case 0xC000008DL: |
| case 0xC000008EL: |
| case 0xC0000094L: |
| case 0xC0020044L: |
| case 0xC0020046L: return EDOM; |
| case 0xC0000091L: |
| case 0xC0000093L: |
| case 0xC00001A1L: |
| case 0xC002002BL: |
| case 0xC002002CL: |
| case 0xC002002EL: |
| case 0xC0020047L: |
| case 0xC0020048L: |
| case 0xC003000BL: return ERANGE; |
| case 0xC0000098L: |
| case 0xC00000ACL: |
| case 0xC00000AFL: |
| case 0xC00000B1L: |
| case 0xC00000B6L: |
| case 0xC0000128L: |
| case 0xC0000140L: |
| case 0xC003005FL: return EBADF; |
| case 0xC000009DL: |
| case 0xC0000285L: |
| case 0xC0000464L: return ENXIO; |
| case 0xC00000A2L: return EROFS; |
| case 0xC00000A3L: return ENOMEDIUM; |
| case 0xC00000A9L: return EMEDIUMTYPE; |
| case 0xC00000ABL: |
| case 0xC000011FL: return EMFILE; |
| case 0xC00000ADL: |
| case 0xC00000B0L: |
| case 0xC000014BL: return EPIPE; |
| case 0xC00000BAL: return EISDIR; |
| case 0xC00000BDL: |
| case 0xC00000E0L: return ENOTUNIQ; |
| case 0xC00000BEL: |
| case 0xC000023CL: return ENETUNREACH; |
| case 0xC00000C5L: |
| case 0xC00000D2L: |
| case 0xC000029EL: |
| case 0xC000A080L: |
| case 0xC000A081L: return EREMOTEIO; |
| case 0xC00000C8L: |
| case 0xC0000120L: return ECANCELED; |
| case 0xC00000CEL: |
| case 0xC00000D0L: |
| case 0xC0000196L: |
| case 0xC0000246L: |
| case 0xC0000259L: return EUSERS; |
| case 0xC00000CFL: |
| case 0xC00000D1L: |
| case 0xC00000D8L: |
| case 0xC00000D9L: |
| case 0xC000022DL: return EAGAIN; |
| case 0xC00000D3L: return ENFILE; |
| case 0xC00000D4L: return EXDEV; |
| case 0xC00000D6L: |
| case 0xC000013FL: |
| case 0xC0000210L: |
| case 0xC00A0026L: return ETIMEDOUT; |
| case 0xC0000101L: |
| case 0xC0000180L: return ENOTEMPTY; |
| case 0xC0000106L: return ENAMETOOLONG; |
| case 0xC0000138L: |
| case 0xC0000251L: return ELIBBAD; |
| case 0xC000013EL: return EPROTO; |
| case 0xC0000194L: return EDEADLK; |
| case 0xC000020DL: return ECONNRESET; |
| case 0xC000023DL: return EHOSTUNREACH; |
| case 0xC0000265L: return EMLINK; |
| case 0xC00002F1L: return ENONET; |
| case 0xC0000350L: return EHOSTDOWN; |
| case 0xC000036FL: return ELIBACC; |
| case 0xC0000904L: return EFBIG; |
| case 0xC002004DL: |
| case 0xC0030006L: return EBADFD; |
| } |
| return __ntstatus_to_errno_other(ntstatus); |
| } |
| |
| #endif |
| |
| int __set_errno_from_ntstatus(long int ntstatus) { |
| return errno_private = __ntstatus_to_errno(ntstatus); |
| } |
| |
| int *_errno() { |
| return &errno_private; |
| } |