error是一个包含在<errno.h>中的预定义的外部int变量,用于表示最近一个函数调用是否产生了错误。若为0,则无错误,其它值均表示一类错误。

perror()和strerror()函数可以把errno的值转化为有意义的字符输出。

 perror()和 strerror 使用:

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <stdlib.h>
int main(){
extern int errno;
errno = ;
opendir("");
printf("errno %d\n", errno);
if(errno!=){
perror("opendir");
}
if(errno!=){
printf("%s\n", strerror(errno));
}
return ;
}

执行结果:

打印出当前linux 系统支持的所有的错误号:

#include <stdio.h>
#include <errno.h>
#include <string.h>
int main(){
for(int i=;i< ; i++)
printf("errno:%d -> %s\n", i, strerror(i));
return ;
}

 当前系统所有错误号:

errno: -> Success
errno: -> Operation not permitted
errno: -> No such file or directory
errno: -> No such process
errno: -> Interrupted system call
errno: -> Input/output error
errno: -> No such device or address
errno: -> Argument list too long
errno: -> Exec format error
errno: -> Bad file descriptor
errno: -> No child processes
errno: -> Resource temporarily unavailable
errno: -> Cannot allocate memory
errno: -> Permission denied
errno: -> Bad address
errno: -> Block device required
errno: -> Device or resource busy
errno: -> File exists
errno: -> Invalid cross-device link
errno: -> No such device
errno: -> Not a directory
errno: -> Is a directory
errno: -> Invalid argument
errno: -> Too many open files in system
errno: -> Too many open files
errno: -> Inappropriate ioctl for device
errno: -> Text file busy
errno: -> File too large
errno: -> No space left on device
errno: -> Illegal seek
errno: -> Read-only file system
errno: -> Too many links
errno: -> Broken pipe
errno: -> Numerical argument out of domain
errno: -> Numerical result out of range
errno: -> Resource deadlock avoided
errno: -> File name too long
errno: -> No locks available
errno: -> Function not implemented
errno: -> Directory not empty
errno: -> Too many levels of symbolic links
errno: -> Unknown error
errno: -> No message of desired type
errno: -> Identifier removed
errno: -> Channel number out of range
errno: -> Level not synchronized
errno: -> Level halted
errno: -> Level reset
errno: -> Link number out of range
errno: -> Protocol driver not attached
errno: -> No CSI structure available
errno: -> Level halted
errno: -> Invalid exchange
errno: -> Invalid request descriptor
errno: -> Exchange full
errno: -> No anode
errno: -> Invalid request code
errno: -> Invalid slot
errno: -> Unknown error
errno: -> Bad font file format
errno: -> Device not a stream
errno: -> No data available
errno: -> Timer expired
errno: -> Out of streams resources
errno: -> Machine is not on the network
errno: -> Package not installed
errno: -> Object is remote
errno: -> Link has been severed
errno: -> Advertise error
errno: -> Srmount error
errno: -> Communication error on send
errno: -> Protocol error
errno: -> Multihop attempted
errno: -> RFS specific error
errno: -> Bad message
errno: -> Value too large for defined data type
errno: -> Name not unique on network
errno: -> File descriptor in bad state
errno: -> Remote address changed
errno: -> Can not access a needed shared library
errno: -> Accessing a corrupted shared library
errno: -> .lib section in a.out corrupted
errno: -> Attempting to link in too many shared libraries
errno: -> Cannot exec a shared library directly
errno: -> Invalid or incomplete multibyte or wide character
errno: -> Interrupted system call should be restarted
errno: -> Streams pipe error
errno: -> Too many users
errno: -> Socket operation on non-socket
errno: -> Destination address required
errno: -> Message too long
errno: -> Protocol wrong type for socket
errno: -> Protocol not available
errno: -> Protocol not supported
errno: -> Socket type not supported
errno: -> Operation not supported
errno: -> Protocol family not supported
errno: -> Address family not supported by protocol
errno: -> Address already in use
errno: -> Cannot assign requested address
errno: -> Network is down
errno: -> Network is unreachable
errno: -> Network dropped connection on reset
errno: -> Software caused connection abort
errno: -> Connection reset by peer
errno: -> No buffer space available
errno: -> Transport endpoint is already connected
errno: -> Transport endpoint is not connected
errno: -> Cannot send after transport endpoint shutdown
errno: -> Too many references: cannot splice
errno: -> Connection timed out
errno: -> Connection refused
errno: -> Host is down
errno: -> No route to host
errno: -> Operation already in progress
errno: -> Operation now in progress
errno: -> Stale file handle
errno: -> Structure needs cleaning
errno: -> Not a XENIX named type file
errno: -> No XENIX semaphores available
errno: -> Is a named type file
errno: -> Remote I/O error
errno: -> Disk quota exceeded
errno: -> No medium found
errno: -> Wrong medium type
errno: -> Operation canceled
errno: -> Required key not available
errno: -> Key has expired
errno: -> Key has been revoked
errno: -> Key was rejected by service
errno: -> Owner died
errno: -> State not recoverable
errno: -> Operation not possible due to RF-kill
errno: -> Memory page has hardware error
errno: -> Unknown error
errno: -> Unknown error
errno: -> Unknown error
errno: -> Unknown error
errno: -> Unknown error
errno: -> Unknown error

保持更新,转载请注明出处。

errno 的使用的更多相关文章

  1. ERROR 1010 (HY000): Error dropping database (can't rmdir './test/', errno: 17)

    在删除数据库的时候报标题所示错误 mysql> drop database test; ERROR (HY000): Error dropping database (can't rmdir ' ...

  2. Linux ERRNO

    摘自Linux-3.18.20的头文件include/uapi/asm-generic/errno-base.h和include/uapi/asm-generic/errno.h: #define E ...

  3. C标准头文件<errno.h>

    声明了错误处理相关的宏 errno errno即error number,在程序启动时被设为0,当某个库函数运行出现错误的时候,会将相应的能表达错误类型的数字赋值给这个左值,这些数字往往有相应的宏来表 ...

  4. C 标准库系列之errno.h

    errno.h 提供了一个整数全局变量errno,当系统调用或者库函数的错误事件发生时可能会修改该值,指明错误的原因,该值可在任何需要的地方被修改:一般情况不为0的值表示出现了异常或者错误. errn ...

  5. macosx 10.11 python pip install 出现错误OSError: [Errno 1] Operation not permitted:

    Exception: Traceback (most recent call last): File , in main status = self.run(options, args) File , ...

  6. MongoDB 由于目标计算机积极拒绝,无法连接 2014-07-25T11:00:48.634+0800 warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061

    转载自:http://www.cnblogs.com/xiaoit/p/3867573.html 1:启动MongoDB 2014-07-25T11:00:48.634+0800 warning: F ...

  7. errno

    关于errno有以下需要注意: 1  A common mistake is to do if (somecall() == -1) {                printf("som ...

  8. mysql errno 150

    mysql error Number 1005can't creat table'/test/#sql-640_1.frm'(errno:150)三种可能问题 外键和被引用外键类型不一样,比如inte ...

  9. 安装Cocoapods时候ERROR: While executing gem ... (Errno::EPERM)

    OS X 10.11 安装Cocoapods 出现问题的解决方法 今天尝试用 Cocoapods安装个第三方库.. 输入pod install, 发现 command not find. WTF! 估 ...

  10. SYMBDSNAP_SDK[3943]: Failed to open device: /dev/symbdsnapctl, errno: 2

    在Linux的日志/var/log/message里面看到下面错误信息: Oct 26 09:48:42 xxxxxxx SYMBDSNAP_SDK[3943]: Failed to open dev ...

随机推荐

  1. Git使用基础介绍

    git教程:一.git的简介:    -git是分布式版本控制系统由Linus为Linux用C语言写的.  -什么是集中式版本控制系统:       版本库是集中存放在中央服务器,干活的时候用自己的电 ...

  2. 13.Git分支-变基(rebase)、rebase VS merge

    1.变基的基本操作 在Git中整合来自不同分支的修改主要有两种方法:merge和rebase. 看下面的例子: 开发任务分叉到了两个不同的分支,并且都有了新的提交. 这时候我们可以使用 git mer ...

  3. 搭建自己的hexo博客

    这是我最近用hexo搭建的个人博客,欢迎来参观留言,以下是我创建这个hexo的一步步步骤,欢迎指正! 我的博客 参考自 潘柏信的博客;CnFeat 主题参考这里 pacman; 主题选自这里 hexa ...

  4. 用abp vNext快速开发Quartz.NET定时任务管理界面

    今天这篇文章我将通过实例代码带着大家一步一步通过abp vNext这个asp.net core的快速开发框架来进行Quartz.net定时任务调度的管理界面的开发.大伙最好跟着一起敲一下代码,当然源码 ...

  5. IView组件化之部署及按钮学习

    IView是什么? iView 是一套基于 Vue.js 的开源 UI 组件库,主要服务于 PC 界面的中后台产品. Npm安装IView npm install iview 在main.js中配置I ...

  6. linux-centerOs6.8安装nginx与配置

    一:安装nginx 1.安装gcc(命令:yum install gcc)备注:可以输入gcc -v查询版本信息,查看是否自带安装 2.安装pcre(命令:yum install pcre-devel ...

  7. Web Api Self-Host

    今天有在研究SignalR, 发现SignalR可以使用Self-Host的方式,就突发奇想,Web Api是不是也可以使用Self-Host的方式寄宿在Console Application或者其他 ...

  8. Redis【入门】就这一篇!

    Redis 概述 在我们日常的Java Web开发中,无不都是使用数据库来进行数据的存储,由于一般的系统任务中通常不会存在高并发的情况,所以这样看起来并没有什么问题,可是一旦涉及大数据量的需求,比如一 ...

  9. 【Java基础】【12String类】

    12.01_常见对象(Scanner的概述和方法介绍)(掌握) A:Scanner的概述 B:Scanner的构造方法原理 Scanner(InputStream source) System类下有一 ...

  10. [七]JavaIO之 PipedInputStream 和 PipedInputStream

    管道简介