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 ...
随机推荐
- virtuoso操作graph的方法--查询和删除
在virtuoso中查看某个graph的数据,直接用sparql语句查询就可以了,对graph进行查询也可以通过sparql实现,删除graph则要在isql中操作. 1 查询graph的命令 在lo ...
- java多线程(8)---阻塞队列
阻塞队列 再写阻塞列队之前,我写了一篇有关queue集合相关博客,也主要是为这篇做铺垫的. 网址:[java提高]---queue集合 在这篇博客中我们接触的队列都是非阻塞队列,比如Priority ...
- TP3.2框架中的字母函数解析
C的使用方法以及注意事项 使用方法: 1.读取配置 C('参数名称') 配置参数不区分大小写,存在则设置,否则返回NULL; 因为配置参数是全局有效的,因此C方法可以在任何地方读取任何配置,即使某个 ...
- Kafka~HelloWorld得来不易
今天连搭了zookeeper和kafka的环境,并部署成功,但在.net驱动的操作下,没有消费成功,原因何在? 防火墙 zookeeper没运行? kafka没有公开IP? 第一感觉也就是这向个原因了 ...
- Django中的templates(你的HTML页面放哪里)
本文回答Django里面的HTML文件应该怎么放,以及Django是如何查找模板文件的. 到目前为止我们没有使用HTML页面,在之前的说明中所有内容都是写死在程序里的,如果你想改变内容就要修改代码.但 ...
- 修改sql数据库名称
USE master; GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@SQL+'; KILL '+RTRIM(SPID) FROM ma ...
- 性能测试-Jmeter3.1 使用技巧
一.JMeter官网 下载地址 http://jmeter.apache.org/download_jmeter.cgi Jmeter wiki https://wiki.apache.org/jme ...
- [ SSH框架 ] Spring框架学习之一
一.Spring概述 1.1 什么是Spring Spring是一个开源框架, Spring是于2003年兴起的一个轻量级的Java开发框架,由 Rod Johnson在其著作 Expert One- ...
- 支持异步写入的日志类,支持Framework2.0
因为工作需要需要在XP上运行一个C#编写的Winform插件,我就用Framework2.0,因为存在接口交互所以想保留交易过程的入参出参. 考虑到插件本身实施的因素,就没有使用Log4.NLog等成 ...
- SpringMvc 请求中日期类型参数接收一二事儿
首先说明:以版本为Spring 4.3.0为测试对象: 开启<mvc:annotation-driven /> 测试场景一:请求中含有date属性,该类型为日期类型,SpringMvc采用 ...