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 ... 
随机推荐
- 如何为自己的pip包打造可以执行的系统命令
			1.我们在打包我们自己的Python Package的时候.我们不仅可以在代码中使用我们的package,而且可以添加一些可执行命令来执行自己的函数. 2 .我们应该怎么办呢? 1.首先新建目录以及文 ... 
- Python内置函数(5)——bin
			英文文档: bin(x) Convert an integer number to a binary string. The result is a valid Python expression. ... 
- Java异常处理:给程序罩一层保险
			文/沉默王二 人这一生,总会遇到一些不可预料的麻烦,这些麻烦可能会让我们遭受沉重的打击.为了减轻因此承受的负担,我们就会买保险. 本着负责任的态度,我们程序员在写代码的时候,都非常的严谨.但程序在运行 ... 
- 【Python3爬虫】猫眼电影爬虫(破解字符集反爬)
			一.页面分析 首先打开猫眼电影,然后点击一个正在热播的电影(比如:毒液).打开开发者工具,点击左上角的箭头,然后用鼠标点击网页上的票价,可以看到源码中显示的不是数字,而是某些根本看不懂的字符,这是因为 ... 
- shell实战之tomcat看门狗
			1.脚本简介 tomcat看门狗,在tomcat进程异常退出时会自动拉起tomcat进程并记录tomcat运行的日志. 函数说明: log_info:打印日志的函数,入参为需要在日志中打印的msg s ... 
- python学习第三讲,python基础语法之注释,算数运算符,变量.
			目录 python学习第三讲,python基础语法之注释,算数运算符,变量. 一丶python中的基础语法,注释,算数运算符,变量 1.python中的注释 2.python中的运算符. 3.pyth ... 
- VS 2015 GIT操作使用说明
			相比VS2013,VS2015在对GIT的支持上有了更强大的支持.本篇仅作抛砖引玉,不做过多介绍: 1. 打开VS 2015起始页 2. 打开团队资源管理器 打开[本地GIT存储库]选项卡,然后点击[ ... 
- 学JAVA第三天,JAVA第二章《JAVA数据类型》
			---恢复内容开始--- <JAVA数据类型> 我们一般都用int类型,因为int类行一般的日常生活的数据都能满足了. 当然,想李嘉诚,马云这种有钱人,int类行就不能满足帮他记钱的了,像 ... 
- 教我徒弟Android开发入门(四)
			本期知识点: 两大常用布局的简单介绍 在我们的APP使用第三方库 Android Studio常用快捷键 一.两大常用布局 1.LinearLayout线性布局 线性布局,可以垂直显示或者水平显示,设 ... 
- js  autocomplete输入延迟触发执行事件
			需求:延迟查询,autocomplete延迟触发执行事件.当有下一个事件开始时,本次事件中断.目的是为了防止调用服务器过于频繁. var timeout = 0;//延时处理 $("#cus ... 
