errno 的使用
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 的使用的更多相关文章
- ERROR 1010 (HY000): Error dropping database (can't rmdir './test/', errno: 17)
在删除数据库的时候报标题所示错误 mysql> drop database test; ERROR (HY000): Error dropping database (can't rmdir ' ...
- Linux ERRNO
摘自Linux-3.18.20的头文件include/uapi/asm-generic/errno-base.h和include/uapi/asm-generic/errno.h: #define E ...
- C标准头文件<errno.h>
声明了错误处理相关的宏 errno errno即error number,在程序启动时被设为0,当某个库函数运行出现错误的时候,会将相应的能表达错误类型的数字赋值给这个左值,这些数字往往有相应的宏来表 ...
- C 标准库系列之errno.h
errno.h 提供了一个整数全局变量errno,当系统调用或者库函数的错误事件发生时可能会修改该值,指明错误的原因,该值可在任何需要的地方被修改:一般情况不为0的值表示出现了异常或者错误. errn ...
- 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 , ...
- 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 ...
- errno
关于errno有以下需要注意: 1 A common mistake is to do if (somecall() == -1) { printf("som ...
- mysql errno 150
mysql error Number 1005can't creat table'/test/#sql-640_1.frm'(errno:150)三种可能问题 外键和被引用外键类型不一样,比如inte ...
- 安装Cocoapods时候ERROR: While executing gem ... (Errno::EPERM)
OS X 10.11 安装Cocoapods 出现问题的解决方法 今天尝试用 Cocoapods安装个第三方库.. 输入pod install, 发现 command not find. WTF! 估 ...
- 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 ...
随机推荐
- hadoop退出安全模式Name node is in safe mode
在使用 hdfs 的时候出现如下错误: 18/01/12 09:04:34 INFO fs.TrashPolicyDefault: Namenode trash configuration: Dele ...
- Python内置函数(32)——input
英文文档: input([prompt]) If the prompt argument is present, it is written to standard output without a ...
- AI 这么优秀,连我鉴黄师的饭碗都抢了
色情行业,或许是对信息渠道最敏锐.利用各类信息渠道进行传播最“充分”的“行业”.这些年,社交 App.直播.短视频等新的互联网应用方式,都难逃色情内容的“骚扰”.哪里人多,色情内容就能立刻扑过去,在海 ...
- 【Docker】(3)---linux部署Docker、Docker常用命令
linux部署Docker.Docker常用命令 本次部署Linux版本:CentOS 7.4 64位. 说明: 因为Docker是基于Linux 64bit的 所以Docker要求64位的系统且内核 ...
- log4cplus使用(二)-自定义日志等级
log4cplus支持用户自定义日志等级,操作也比较简单,使用之前贴如下宏定义 #define LOG4CPLUS_MACRO_CREASH_LOG_LEVEL(pred) LOG4CPLUS_UNL ...
- redis 系列11 列表对象
一. 列表对象概述 Redis列表是简单的字符串列表,按照插入顺序排序.你可以添加一个元素到列表的头部(左边)或者尾部(右边).一个列表最多可以包含 232 - 1 个元素 (4294967295, ...
- nginx~linux下的部署
一些概念 Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄 ...
- 爬虫入门(四)——Scrapy框架入门:使用Scrapy框架爬取全书网小说数据
为了入门scrapy框架,昨天写了一个爬取静态小说网站的小程序 下面我们尝试爬取全书网中网游动漫类小说的书籍信息. 一.准备阶段 明确一下爬虫页面分析的思路: 对于书籍列表页:我们需要知道打开单本书籍 ...
- DocX开源WORD操作组件的学习系列二
DocX学习系列 DocX开源WORD操作组件的学习系列一 : http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_sharp_001_docx1.htm ...
- Spring Boot(十一)Redis集成从Docker安装到分布式Session共享
一.简介 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API,Redis也是技术领域使用最为广泛的存储中间件,它是 ...