errno头文件

来源:互联网 发布:剑三毒姐捏脸数据 编辑:程序博客网 时间:2024/06/07 08:46

以前做IO操作时,常常会得到一个errno_t,其实就是整数 typedef int errno_t;

以下是VC的errno头文件,可以看出Error Code定义为一些整数值

[cpp] view plain copy
  1. /*** 
  2. *errno.h - system wide error numbers (set by system calls) 
  3. * 
  4. *       Copyright (c) Microsoft Corporation. All rights reserved. 
  5. * 
  6. *Purpose: 
  7. *       This file defines the system-wide error numbers (set by 
  8. *       system calls).  Conforms to the XENIX standard.  Extended 
  9. *       for compatibility with Uniforum standard. 
  10. *       [System V] 
  11. * 
  12. *       [Public] 
  13. * 
  14. ****/  
  15.   
  16. #pragma once  
  17.   
  18. #ifndef _INC_ERRNO  
  19. #define _INC_ERRNO  
  20.   
  21. #include <crtdefs.h>  
  22.   
  23. #ifdef __cplusplus  
  24. extern "C" {  
  25. #endif  /* __cplusplus */  
  26.   
  27. /* Declare reference to errno */  
  28.   
  29. #ifndef _CRT_ERRNO_DEFINED  
  30. #define _CRT_ERRNO_DEFINED  
  31. _CRTIMP extern int * __cdecl _errno(void);  
  32. #define errno   (*_errno())  
  33.   
  34. errno_t __cdecl _set_errno(_In_ int _Value);  
  35. errno_t __cdecl _get_errno(_Out_ int * _Value);  
  36. #endif  /* _CRT_ERRNO_DEFINED */  
  37.   
  38. /* Error Codes */  
  39.   
  40. #define EPERM           1  
  41. #define ENOENT          2  
  42. #define ESRCH           3  
  43. #define EINTR           4  
  44. #define EIO             5  
  45. #define ENXIO           6  
  46. #define E2BIG           7  
  47. #define ENOEXEC         8  
  48. #define EBADF           9  
  49. #define ECHILD          10  
  50. #define EAGAIN          11  
  51. #define ENOMEM          12  
  52. #define EACCES          13  
  53. #define EFAULT          14  
  54. #define EBUSY           16  
  55. #define EEXIST          17  
  56. #define EXDEV           18  
  57. #define ENODEV          19  
  58. #define ENOTDIR         20  
  59. #define EISDIR          21  
  60. #define ENFILE          23  
  61. #define EMFILE          24  
  62. #define ENOTTY          25  
  63. #define EFBIG           27  
  64. #define ENOSPC          28  
  65. #define ESPIPE          29  
  66. #define EROFS           30  
  67. #define EMLINK          31  
  68. #define EPIPE           32  
  69. #define EDOM            33  
  70. #define EDEADLK         36  
  71. #define ENAMETOOLONG    38  
  72. #define ENOLCK          39  
  73. #define ENOSYS          40  
  74. #define ENOTEMPTY       41  
  75.   
  76. /* Error codes used in the Secure CRT functions */  
  77.   
  78. #ifndef RC_INVOKED  
  79. #if !defined (_SECURECRT_ERRCODE_VALUES_DEFINED)  
  80. #define _SECURECRT_ERRCODE_VALUES_DEFINED  
  81. #define EINVAL          22  
  82. #define ERANGE          34  
  83. #define EILSEQ          42  
  84. #define STRUNCATE       80  
  85. #endif  /* !defined (_SECURECRT_ERRCODE_VALUES_DEFINED) */  
  86. #endif  /* RC_INVOKED */  
  87.   
  88. /* Support EDEADLOCK for compatibility with older MS-C versions */  
  89. #define EDEADLOCK       EDEADLK  
  90.   
  91. /* POSIX SUPPLEMENT */  
  92. #define EADDRINUSE      100  
  93. #define EADDRNOTAVAIL   101  
  94. #define EAFNOSUPPORT    102  
  95. #define EALREADY        103  
  96. #define EBADMSG         104  
  97. #define ECANCELED       105  
  98. #define ECONNABORTED    106  
  99. #define ECONNREFUSED    107  
  100. #define ECONNRESET      108  
  101. #define EDESTADDRREQ    109  
  102. #define EHOSTUNREACH    110  
  103. #define EIDRM           111  
  104. #define EINPROGRESS     112  
  105. #define EISCONN         113  
  106. #define ELOOP           114  
  107. #define EMSGSIZE        115  
  108. #define ENETDOWN        116  
  109. #define ENETRESET       117  
  110. #define ENETUNREACH     118  
  111. #define ENOBUFS         119  
  112. #define ENODATA         120  
  113. #define ENOLINK         121  
  114. #define ENOMSG          122  
  115. #define ENOPROTOOPT     123  
  116. #define ENOSR           124  
  117. #define ENOSTR          125  
  118. #define ENOTCONN        126  
  119. #define ENOTRECOVERABLE 127  
  120. #define ENOTSOCK        128  
  121. #define ENOTSUP         129  
  122. #define EOPNOTSUPP      130  
  123. #define EOTHER          131  
  124. #define EOVERFLOW       132  
  125. #define EOWNERDEAD      133  
  126. #define EPROTO          134  
  127. #define EPROTONOSUPPORT 135  
  128. #define EPROTOTYPE      136  
  129. #define ETIME           137  
  130. #define ETIMEDOUT       138  
  131. #define ETXTBSY         139  
  132. #define EWOULDBLOCK     140  
  133.   
  134. #ifdef __cplusplus  
  135. }  
  136. #endif  /* __cplusplus */  
  137.   
  138. #endif  /* _INC_ERRNO */  

贴在这方便以后查看微笑

但每次对表岂不麻烦,还好好在string.h中已经定义好了通过错误码得到说明的函数 strerror

试试

[cpp] view plain copy
  1. #include <string.h>  
  2. #include <errno.h>  
  3.   
  4. int main(int argc, char* argv[])  
  5. {  
  6.       
  7.     for (int i = 1; i < 141; i++)  
  8.     {  
  9.         char* msg = strerror(i);  
  10.         printf("%d : %s\n", i, msg);  
  11.     }  
  12.       
  13.     getchar();  
  14.       
  15.     return 0;  
  16. }  

发现42号之后全是 Unknown error,原因是 errno 中定义之后的是兼容 Older version C的,或者是别的什么,还不清楚。?


原创粉丝点击