log 里报错,errno:4   与errno:2

查了一下 errno.h   --------下文来自百度百科

errno

编辑

errno 是记录系统的最后一次错误代码。代码是一个int型的值,在errno.h中定义
中文名
errno
查    看
错误代码errno调试程序重要方法
代    码
是一个int型的值
通    过
查看该值推测出错的原因

NAME

编辑

errno - number of last error
if (somecall() == -1) {
printf("somecall() failed\n");
if (errno == ...) { ... }
}
这样的例子并不能得到somecall这个函数的运行所产生的错误代码,因为很可能是printf这个函数产生的。
if (somecall() == -1) {
int errsv = errno;
printf("somecall() failed\n");
if (errsv == ...) { ... }
这样才能真正得到运行somecall函数所带来的错误代码。
}
注意:只有当一个库函数失败时,errno才会被设置。当函数成功运行时,errno的值不会被修改。这意味着我们不能通过测试errno的值来判断是否有错误存在。反之,只有当被调用的函数提示有错误发生时检查errno的值才有意义。
查看错误代码errno是调试程序的一个重要方法。当linux C api函数发生异常时,一般会将errno变量(需include errno.h)赋一个整数值,不同的值表示不同的含义,可以通过查看该值推测出错的原因。在实际编程中用这一招解决了不少原本看来莫名其妙的问题。

errno的一些错误定义

编辑

以下主要来自2.6.32的内核代码中的/usr/include/asm-generic/errno.h及errno-base.h,输出错误原因定义归纳整理如下:
#define EPERM 1 /* Operation not permitted */
  #define ENOENT 2 /* No such file or directory */
  #define ESRCH 3 /* No such process */
  #define EINTR 4 /* Interrupted system call */
  #define EIO 5 /* I/O error */
  #define ENXIO 6 /* No such device or address */
  #define E2BIG 7 /* Argument list too long */
  #define ENOEXEC 8 /* Exec format error */
  #define EBADF 9 /* Bad file number */
  #define ECHILD 10 /* No child processes */
  #define EAGAIN 11 /* Try again */
  #define ENOMEM 12 /* Out of memory */
  #define EACCES 13 /* Permission denied */
  #define EFAULT 14 /* Bad address */
  #define ENOTBLK 15 /* Block device required */
  #define EBUSY 16 /* Device or resource busy */
  #define EEXIST 17 /* File exists */
  #define EXDEV 18 /* Cross-device link */
  #define ENODEV 19 /* No such device */
  #define ENOTDIR 20 /* Not a directory */
  #define EISDIR 21 /* Is a directory */
  #define EINVAL 22 /* Invalid argument */
  #define ENFILE 23 /* File table overflow */
  #define EMFILE 24 /* Too many open files */
  #define ENOTTY 25 /* Not a typewriter */
  #define ETXTBSY 26 /* Text file busy */
  #define EFBIG 27 /* File too large */
  #define ENOSPC 28 /* No space left on device */
  #define ESPIPE 29 /* Illegal seek */
  #define EROFS 30 /* Read-only file system */
  #define EMLINK 31 /* Too many links */
  #define EPIPE 32 /* Broken pipe */
  #define EDOM 33 /* Math argument out of domain of func */
  #define ERANGE 34 /* Math result not representable */
  #define EDEADLK 35 /* Resource deadlock would occur */
  #define ENAMETOOLONG 36 /* File name too long */
  #define ENOLCK 37 /* No record locks available */
  #define ENOSYS 38 /* Function not implemented */
  #define ENOTEMPTY 39 /* Directory not empty */
  #define ELOOP 40 /* Too many symbolic links encountered */
  #define EWOULDBLOCK EAGAIN /* Operation would block */
  #define ENOMSG 42 /* No message of desired type */
  #define EIDRM 43 /* Identifier removed */
  #define ECHRNG 44 /* Channel number out of range */
  #define EL2NSYNC 45 /* Level 2 not synchronized */
  #define EL3HLT 46 /* Level 3 halted */
  #define EL3RST 47 /* Level 3 reset */
  #define ELNRNG 48 /* Link number out of range */
  #define EUNATCH 49 /* Protocol driver not attached */
  #define ENOCSI 50 /* No CSI structure available */
  #define EL2HLT 51 /* Level 2 halted */
  #define EBADE 52 /* Invalid exchange */
  #define EBADR 53 /* Invalid request descriptor */
  #define EXFULL 54 /* Exchange full */
  #define ENOANO 55 /* No anode */
  #define EBADRQC 56 /* Invalid request code */
  #define EBADSLT 57 /* Invalid slot */
  #define EDEADLOCK EDEADLK
  #define EBFONT 59 /* Bad font file format */
  #define ENOSTR 60 /* Device not a stream */
  #define ENODATA 61 /* No data available */
  #define ETIME 62 /* Timer expired */
  #define ENOSR 63 /* Out of streams resources */
  #define ENONET 64 /* Machine is not on the network */
  #define ENOPKG 65 /* Package not installed */
  #define EREMOTE 66 /* Object is remote */
  #define ENOLINK 67 /* Link has been severed */
  #define EADV 68 /* Advertise error */
  #define ESRMNT 69 /* Srmount error */
  #define ECOMM 70 /* Communication error on send */
  #define EPROTO 71 /* Protocol error */
  #define EMULTIHOP 72 /* Multihop attempted */
  #define EDOTDOT 73 /* RFS specific error */
  #define EBADMSG 74 /* Not a data message */
  #define EOVERFLOW 75 /* Value too large for defined data type */
  #define ENOTUNIQ 76 /* Name not unique on network */
  #define EBADFD 77 /* File descriptor in bad state */
  #define EREMCHG 78 /* Remote address changed */
  #define ELIBACC 79 /* Can not access a needed shared library */
  #define ELIBBAD 80 /* Accessing a corrupted shared library */
  #define ELIBSCN 81 /* .lib section in a.out corrupted */
  #define ELIBMAX 82 /* Attempting to link in too many shared libraries */
  #define ELIBEXEC 83 /* Cannot exec a shared library directly */
  #define EILSEQ 84 /* Illegal byte sequence */
  #define ERESTART 85 /* Interrupted system call should be restarted */
  #define ESTRPIPE 86 /* Streams pipe error */
  #define EUSERS 87 /* Too many users */
  #define ENOTSOCK 88 /* Socket operation on non-socket */
  #define EDESTADDRREQ 89 /* Destination address required */
  #define EMSGSIZE 90 /* Message too long */
  #define EPROTOTYPE 91 /* Protocol wrong type for socket */
  #define ENOPROTOOPT 92 /* Protocol not available */
  #define EPROTONOSUPPORT 93 /* Protocol not supported */
  #define ESOCKTNOSUPPORT 94 /* Socket type not supported */
  #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
  #define EPFNOSUPPORT 96 /* Protocol family not supported */
  #define EAFNOSUPPORT 97 /* Address family not supported by protocol */
  #define EADDRINUSE 98 /* Address already in use */
  #define EADDRNOTAVAIL 99 /* Cannot assign requested address */
  #define ENETDOWN 100 /* Network is down */
  #define ENETUNREACH 101 /* Network is unreachable */
  #define ENETRESET 102 /* Network dropped connection because of reset */
  #define ECONNABORTED 103 /* Software caused connection abort */
  #define ECONNRESET 104 /* Connection reset by peer */
  #define ENOBUFS 105 /* No buffer space available */
  #define EISCONN 106 /* Transport endpoint is already connected */
  #define ENOTCONN 107 /* Transport endpoint is not connected */
  #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */
  #define ETOOMANYREFS 109 /* Too many references: cannot splice */
  #define ETIMEDOUT 110 /* Connection timed out */
  #define ECONNREFUSED 111 /* Connection refused */
  #define EHOSTDOWN 112 /* Host is down */
  #define EHOSTUNREACH 113 /* No route to host */
  #define EALREADY 114 /* Operation already in progress */
  #define EINPROGRESS 115 /* Operation now in progress */
  #define ESTALE 116 /* Stale NFS file handle */
  #define EUCLEAN 117 /* Structure needs cleaning */
  #define ENOTNAM 118 /* Not a XENIX named type file */
  #define ENAVAIL 119 /* No XENIX semaphores available */
  #define EISNAM 120 /* Is a named type file */
  #define ENOKEY 126 /* Required key not available */
  #define EKEYEXPIRED 127 /* Key has expired */
  #define EKEYREVOKED 128 /* Key has been revoked */
  #define EKEYREJECTED 129 /* Key was rejected by service */
  #define EOWNERDEAD 130 /* Owner died */
  #define ENOTRECOVERABLE 131 /* State not recoverable */
  #define ERFKILL 132 /* Operation not possible due to RF-kill */
  #define EHWPOISON 133 /* Memory page has hardware error */

标准库errno.h 查看错误代码编号,errno:4 与error:2的更多相关文章

  1. C 标准库 - <math.h>

    C 标准库 - <math.h> 简介 math.h 头文件定义了各种数学函数和一个宏.在这个库中所有可用的功能都带有一个 double 类型的参数,且都返回 double类型的结果. 库 ...

  2. C 标准库 - ctype.h

    C 标准库 - ctype.h This header declares a set of functions to classify and transform individual charact ...

  3. C 标准库 - string.h

    C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...

  4. C 标准库 - <assert.h>

    C 标准库 - <assert.h> 简介 C 标准库的 assert.h头文件提供了一个名为 assert 的宏,它可用于验证程序做出的假设,并在假设为假时输出诊断消息. 已定义的宏 a ...

  5. C 标准库 - <stdarg.h>

    C 标准库 - <stdarg.h> 简介 stdarg.h 头文件定义了一个变量类型 va_list 和三个宏,这三个宏可用于在参数个数未知(即参数个数可变)时获取函数中的参数. 可变参 ...

  6. C 标准库 - <signal.h>

    C 标准库 - <signal.h> 简介 signal.h 头文件定义了一个变量类型 sig_atomic_t.两个函数调用和一些宏来处理程序执行期间报告的不同信号. 库变量 下面是头文 ...

  7. C 标准库 - <setjmp.h>

    C 标准库 - <setjmp.h> 简介 setjmp.h 头文件定义了宏 setjmp().函数 longjmp() 和变量类型 jmp_buf,该变量类型会绕过正常的函数调用和返回规 ...

  8. C 标准库 - <locale.h>

    C 标准库 - <locale.h> 简介 locale.h 头文件定义了特定地域的设置,比如日期格式和货币符号.接下来我们将介绍一些宏,以及一个重要的结构 struct lconv 和两 ...

  9. C 标准库 - <limits.h>

    C 标准库 - <limits.h> 简介 limits.h 头文件决定了各种变量类型的各种属性.定义在该头文件中的宏限制了各种变量类型(比如 char.int 和 long)的值. 这些 ...

随机推荐

  1. [CareerCup] 11.4 Sort the File 文件排序

    11.4 Imagine you have a 20 GB file with one string per line. Explain how you would sort the file. 这道 ...

  2. 20145208 《Java程序设计》第10周学习总结

    20145208 <Java程序设计>第10周学习总结 教材学习内容总结 了解JAVA网络编程的基础知识 这一部分知识的学习在我的实验中有叙述实验五 补充内容: 在现有的网络中,网络通讯的 ...

  3. <实训|第三天>Linux登录界面的修改以及Richard Stallman、自由软件运动

    在写博客之前我想说两点: 承认一个错误,昨天写的实训第二天,我把redhat6.7写成了Linux6.7,感谢热心人士的指出! 昨天写的文章名字太长了,今天改善,内容感觉表述不全,希望各位谅解! 官方 ...

  4. ASP.NET MVC5 插件化机制简单实现

    一.前言 nopCommerce的插件机制的核心是使用BuildManager.AddReferencedAssembly将使用Assembly.Load加载的插件程序集添加到应用程序域的引用中.具体 ...

  5. jdbc基础 (五) 连接池与数据源 DBCP以及C3P0的使用

    一.连接池的概念和使用 在实际应用开发中,特别是在WEB应用系统中,如果JSP.Servlet或EJB使用JDBC直接访问数据库中的数据,每一次数据访问请求都必须经历建立数据库连接.打开数据库.存取数 ...

  6. sublime 插件的安装

    sublime(text3)插件的安装 之前一直对sublime插件的安装搞不懂,导致自己不能充分地运用它的便捷性.昨天仔细看了下百度,恍然大悟,一下子把必备的插件都装了: 对于插件的安装,首先要在s ...

  7. [转]C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe

    写在前面 原文地址:C#创建服务及使用程序自动安装服务,.NET创建一个即是可执行程序又是Windows服务的exe 这篇文章躺在我的收藏夹中有很长一段时间了,今天闲着没事,就自己动手实践了一下.感觉 ...

  8. JavaScript表单处理(上)

    为了分担服务器处理表单的压力,JavaScript提供了一些解决方案,从而大大打破了处处依赖服务器的局面.  发文不易,转载请亲注明出处,谢谢! 一.表单介绍 在HTML中,表单是由<form& ...

  9. [转载]NSString中判断中文,英文,数字

    曾有需求做个用户名中非法字符的判断,要求是只能输入中英文和数字,其他字符一律非法,故写了下边一个程序mark一下吧~~ NSString *testString = @"春1mianBU觉晓 ...

  10. new-nav-css

    header:before, header:after ,.navigation:before, .navigation:after,.nav-row:before, .nav-row:after,. ...