当前位置: 首页 > news >正文

代码模板-C语言常用的errno的名字、值以及对应关系?转换字符串函数?(errno.h, strerror; errno -l; man errno)

背景

errno.h是C 编程语言标准库中的头文件。它定义了使用符号errno (“错误号”的缩写)报告和检索错误情况的宏。经常需要用来在内核态用户态返回错误寻找,本文以供快速检索。

常用函数与用法

strerror 根据errno获取文件

比如:

    FILE *file = fopen("non_file.txt", "r");if (file == NULL) {// 输出错误信息printf("Error opening file: %s\n", strerror(errno));return EXIT_FAILURE;}

实战输出:
在这里插入图片描述

函数返回

某个地方执行事务可以直接用 return -Exxx 这里的Exxx就是下面的 errorno的宏定义, 比如return -EPERM;表示没有权限

头文件

errno.h

对应关系

#define	EPERM 1		/* Not super-user */
#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		/* Arg list too long */
#define	ENOEXEC 8	/* Exec format error */
#define	EBADF 9		/* Bad file number */
#define	ECHILD 10	/* No children */
#define	EAGAIN 11	/* No more processes */
#define	ENOMEM 12	/* Not enough core */
#define	EACCES 13	/* Permission denied */
#define	EFAULT 14	/* Bad address */
#define	ENOTBLK 15	/* Block device required */
#define	EBUSY 16	/* Mount device 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	/* Too many open files in system */
#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 arg out of domain of func */
#define	ERANGE 34	/* Math result not representable */
#define	ENOMSG 35	/* No message of desired type */
#define	EIDRM 36	/* Identifier removed */
#define	ECHRNG 37	/* Channel number out of range */
#define	EL2NSYNC 38	/* Level 2 not synchronized */
#define	EL3HLT 39	/* Level 3 halted */
#define	EL3RST 40	/* Level 3 reset */
#define	ELNRNG 41	/* Link number out of range */
#define	EUNATCH 42	/* Protocol driver not attached */
#define	ENOCSI 43	/* No CSI structure available */
#define	EL2HLT 44	/* Level 2 halted */
#define	EDEADLK 45	/* Deadlock condition */
#define	ENOLCK 46	/* No record locks available */
#define EBADE 50	/* Invalid exchange */
#define EBADR 51	/* Invalid request descriptor */
#define EXFULL 52	/* Exchange full */
#define ENOANO 53	/* No anode */
#define EBADRQC 54	/* Invalid request code */
#define EBADSLT 55	/* Invalid slot */
#define EDEADLOCK 56	/* File locking deadlock error */
#define EBFONT 57	/* Bad font file fmt */
#define ENOSTR 60	/* Device not a stream */
#define ENODATA 61	/* No data (for no delay io) */
#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	/* The object is remote */
#define ENOLINK 67	/* The 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 74	/* Multihop attempted */
#define	ELBIN 75	/* Inode is remote (not really error) */
#define	EDOTDOT 76	/* Cross mount point (not really error) */
#define EBADMSG 77	/* Trying to read unreadable message */
#define EFTYPE 79	/* Inappropriate file type or format */
#define ENOTUNIQ 80	/* Given log. name not unique */
#define EBADFD 81	/* f.d. invalid for this operation */
#define EREMCHG 82	/* Remote address changed */
#define ELIBACC 83	/* Can't access a needed shared lib */
#define ELIBBAD 84	/* Accessing a corrupted shared lib */
#define ELIBSCN 85	/* .lib section in a.out corrupted */
#define ELIBMAX 86	/* Attempting to link in too many libs */
#define ELIBEXEC 87	/* Attempting to exec a shared library */
#define ENOSYS 88	/* Function not implemented */
#define ENMFILE 89      /* No more files */
#define ENOTEMPTY 90	/* Directory not empty */
#define ENAMETOOLONG 91	/* File or path name too long */
#define ELOOP 92	/* Too many symbolic links */
#define EOPNOTSUPP 95	/* Operation not supported on transport endpoint */
#define EPFNOSUPPORT 96 /* Protocol family not supported */
#define ECONNRESET 104  /* Connection reset by peer */
#define ENOBUFS 105	/* No buffer space available */
#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */
#define EPROTOTYPE 107	/* Protocol wrong type for socket */
#define ENOTSOCK 108	/* Socket operation on non-socket */
#define ENOPROTOOPT 109	/* Protocol not available */
#define ESHUTDOWN 110	/* Can't send after socket shutdown */
#define ECONNREFUSED 111	/* Connection refused */
#define EADDRINUSE 112		/* Address already in use */
#define ECONNABORTED 113	/* Connection aborted */
#define ENETUNREACH 114		/* Network is unreachable */
#define ENETDOWN 115		/* Network interface is not configured */
#define ETIMEDOUT 116		/* Connection timed out */
#define EHOSTDOWN 117		/* Host is down */
#define EHOSTUNREACH 118	/* Host is unreachable */
#define EINPROGRESS 119		/* Connection already in progress */
#define EALREADY 120		/* Socket already connected */
#define EDESTADDRREQ 121	/* Destination address required */
#define EMSGSIZE 122		/* Message too long */
#define EPROTONOSUPPORT 123	/* Unknown protocol */
#define ESOCKTNOSUPPORT 124	/* Socket type not supported */
#define EADDRNOTAVAIL 125	/* Address not available */
#define ENETRESET 126
#define EISCONN 127		/* Socket is already connected */
#define ENOTCONN 128		/* Socket is not connected */
#define ETOOMANYREFS 129
#define EPROCLIM 130
#define EUSERS 131
#define EDQUOT 132
#define ESTALE 133
#define ENOTSUP 134		/* Not supported */
#define ENOMEDIUM 135   /* No medium (in tape drive) */
#define ENOSHARE 136    /* No such host or network path */
#define ECASECLASH 137  /* Filename exists with different case */
#define EILSEQ 138
#define EOVERFLOW 139	/* Value too large for defined data type */

POSIX中的errno

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

其他获取方式

man手册获取 man errno

还可以通过man手册动态获取,命令:man errno
在这里插入图片描述
在这里插入图片描述

使用errno命令获取 errno -l

如果没有需要安装比如ubuntu是 moreutils安装包:apt install moreutils

  • 安装moreutils包安装errno命令
    在这里插入图片描述
  • errno -l 查看输出
    在这里插入图片描述

参考:
https://en.wikipedia.org/wiki/Errno.h

相关文章:

代码模板-C语言常用的errno的名字、值以及对应关系?转换字符串函数?(errno.h, strerror; errno -l; man errno)

背景 errno.h是C 编程语言标准库中的头文件。它定义了使用符号errno (“错误号”的缩写)报告和检索错误情况的宏。经常需要用来在内核态用户态返回错误寻找,本文以供快速检索。 常用函数与用法 strerror 根据errno获取文件 比如&#xff…...

全新免押租赁系统助力商品流通高效安全

内容概要 全新免押租赁系统的推出,可以说是一场商品流通领域的小革命。想象一下,不再为押金烦恼,用户只需通过一个简单的信用评估,就能快速租到所需商品,这种体验简直令人惊喜!这个系统利用代扣支付技术&a…...

5.微服务灰度发布落地实践(rocketmq增强)

文章目录 前言发送端灰度增强订阅端灰度增强 前言 上一篇分析了,在灰度发布实现中为什么要对消息队列灰度发布进行增强。本篇主要介绍如何实现rocketmq 灰度发布的增强. 发送端灰度增强 订阅端灰度增强...

MySql核心面试面试问题解析

MySql核心面试面试问题解析 有时候往往简单的才是最容易失分的!!! MySQL支持哪些存储引擎?有何区别? 答案:常见的存储引擎有InnoDB、MyISAM、Memory等。InnoDB支持事务,MyISAM不支持事务&#x…...

logback之自定义pattern使用的转换器

目录 (1)场景介绍 (2)定义转换器BizCallerConverter (3)logback配置conversionRule (4)测试效果 前文《logback之pattern详解以及源码分析》已经介绍了pattern,以及…...

【MySQL】发展起源与核心架构组件详细介绍

🐇明明跟你说过:个人主页 🏅个人专栏:《MySQL技术精粹》🏅 🔖行路有良友,便是天堂🔖 目录 一、引言 1、MySQL起源背景 2、MySQL发展里程 3、MySQL应用场景 二、MySQL的核心特…...

uni-app 多平台分享实现指南

uni-app 多平台分享实现指南 在移动应用开发中,分享功能是一个非常常见的需求,尤其是在社交媒体、营销活动等场景中。使用 uni-app 进行多平台开发时,可以通过一套代码实现跨平台的分享功能,涵盖微信小程序、H5、App 等多个平台。…...

Spring中的IOC是什么,优缺点有哪些?

目录 IOC的核心概念 IOC的优点 IOC的缺点 使用场景说明 总结 IOC(控制反转)是一种设计思想,用于实现低耦合、高内聚的软件架构。它通过将对象的创建和依赖管理交给外部容器来实现,从而减少对象之间的直接依赖关系。 IOC的核…...

Qt实现使用TCP与RS485串口设备通信————附带详细实践方法

文章目录 0 背景1 协议介绍1.1 modbusRTU协议1.1.1 简介1.1.2 RS485和modbusRTU的关系1.1.3 modbusRTU 协议格式1.1.3.1 0x10写多个保持寄存器1.1.3.2 0x02读多个离散输入寄存器1.1.3.3 0x03读多个保持寄存器1.1.3.4 0x04读多个输入寄存器 1.2 ModbusTCP协议1.2.1 ModbusTCP协议…...

js将object整个实体对象作为参数传递

①将object实体转化成json字符串传递&#xff1a; JSON.stringify(obj) ②将json字符串转化成JSON对象值&#xff1a;JSON.parse(json) 实际应用&#xff1a; <div id"div_notice" stylefont-size:14px; width:100%; height:200px; overflow-y:auto;></di…...

超越局部损失函数的预测-优化方法

1 文章信息 文章名为Leaving the Nest : Going Beyond Local Loss Functions for Predict-Then-Optimize。发表在第38届AAAI Conference on Artificial Intelligence. 作者来自哈佛大学。 2 摘要 预测-优化是一种利用机器学习在不确定性下进行决策的方法框架。其核心研究问…...

PDF预览插件

PDF预览插件 可用于当前页面弹窗形式查看,可增加一些自定义功能 pdf预览插件 代码块: pdfobject.js <div class="pdfwrap"><div class="item"><h3>笑场</h3><div class="tags"><p>李诞</p><i&…...

node.js之---CommonJS 模块

CommonJS概念 在 Node.js 中&#xff0c;CommonJS 是一种模块化规范&#xff0c;它定义了如何在 JavaScript 中创建和使用模块。CommonJS 是 Node.js 使用的默认模块系统。它让开发者能够分离代码&#xff0c;便于重用和维护。 CommonJS 模块的基本特性 模块导出 在 CommonJ…...

关于AI面试系统2025年趋势评估!

在快速发展的科技浪潮中&#xff0c;AI技术正以前所未有的速度渗透到各行各业。企业招聘领域&#xff0c;作为人才选拔的关键环节&#xff0c;也不例外地迎来了AI面试系统的广泛应用和持续创新。2025年&#xff0c;AI面试系统不仅成为企业招聘的主流工具&#xff0c;更在智能化…...

SQL—替换字符串—replace函数用法详解

SQL—替换字符串—replace函数用法详解 REPLACE() 函数——查找一个字符串中的指定子串&#xff0c;并将其替换为另一个子串。 REPLACE(str, old_substring, new_substring)str&#xff1a;要进行替换操作的原始字符串。old_substring&#xff1a;要被替换的子串。new_substri…...

《Vue3实战教程》40:Vue3安全

如果您有疑问&#xff0c;请观看视频教程《Vue3实战教程》 安全​ 报告漏洞​ 当一个漏洞被上报时&#xff0c;它会立刻成为我们最关心的问题&#xff0c;会有全职的贡献者暂时搁置其他所有任务来解决这个问题。如需报告漏洞&#xff0c;请发送电子邮件至 securityvuejs.org。…...

软件项目验收测试需进行哪些测试?软件检测机构分享验收测试作用

在信息技术高速发展的今天&#xff0c;软件项目的验收测试作为软件开发生命周期中至关重要的一环&#xff0c;扮演着不可或缺的角色。软件项目验收测试是在软件开发完成后&#xff0c;依据需求文档和设计规范&#xff0c;对软件系统进行的一项综合性测试。其主要目的是验证开发…...

css实现文字描边

效果 学习啦 -webkit-text-stroke-width&#xff1a; 设置文本描边的宽度&#xff0c;值可以是任何长度单位&#xff08;如 px, em, rem 等&#xff09; -webkit-text-stroke-color&#xff1a;设置文本描边的颜色&#xff0c;值可以是任何颜色值&#xff08;如 red, green, bl…...

(二)当人工智能是一个函数,函数形式怎么选择?ChatGPT的函数又是什么?

在上一篇文章中&#xff0c;我们通过二次函数的例子&#xff0c;讲解了如何训练人工智能。今天&#xff0c;让我们进一步探讨&#xff1a;面对不同的实际问题&#xff0c;应该如何选择合适的函数形式&#xff1f; 一、广告推荐系统中的函数选择 1. 业务目标 想象一下&#x…...

数据挖掘——回归算法

数据挖掘——回归算法 回归算法线性回归最小二乘法优化求解——梯度下降法逻辑回归逻辑回归函数逻辑回归参数估计逻辑回归正则化 决策树回归小结 回归算法 回归分析 如果把其中的一些因素&#xff08;房屋面积&#xff09;作为自变量&#xff0c;而另一些随自变量的变化而变化…...

AIGC与未来的通用人工智能(AGI):从生成内容到智能革命

目录 第一部分&#xff1a;AIGC概述 1.1 什么是生成式人工智能&#xff08;AIGC&#xff09; 1.2 AIGC的应用 第二部分&#xff1a;通用人工智能&#xff08;AGI&#xff09;概述 2.1 什么是通用人工智能&#xff08;AGI&#xff09; 2.2 AGI的关键特征 2.3 当前AGI的挑战 第…...

jQuery学习笔记3

jQuery 事件注册 jQuery 事件处理 <div></div><ul><li>我们都是好孩子</li><li>我们都是好孩子</li><li>我们都是好孩子</li><li>我们都是好孩子</li><li>我们都是好孩子</li></ul><o…...

SpringMVC(六)拦截器

目录 1.什么是拦截器 2.拦截器和过滤器有哪些区别 3.拦截器方法 4.单个拦截器的执行流程 5.使用拦截器实现用户登录权限验证&#xff08;实例&#xff09; 1.先在html目录下写一个login.html文件 2.在controller包下写一个LoginController文件 3.加拦截器 1.创建一个conf…...

单区域OSPF配置实验

1、绘制拓扑图 2、配置ip地址 R0 Router(config)#interface FastEthernet0/0 Router(config-if)#ip address 192.168.1.1 255.255.255.0 Router(config-if)#no shutdown Router(config-if)#exit Router(config)#interface FastEthernet0/1 Router(config-if)#ip address 192.16…...

Linux上vi(vim)编辑器使用教程

vi(vim)是上Linux非常常用的编辑器&#xff0c;很多Linux发行版都默认安装了vi(vim)。vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率。vi是“visual interface”的缩写&#xff0c;vim是vi IMproved(增强版的vi)。在一般的系统管理维护中vi就够用&#xff0c;如果想使用…...

虚拟机图像界面打不开了

今天打开虚拟机的时候图形界面打不开&#xff0c;进入到tty1中&#xff0c;而且还没有网&#xff0c;找了好几个办法都不行最后找到这个博主发的&#xff0c;解决了 修复 https://www.cnblogs.com/shuimuqingyang/p/15070690.html...

《经典力学》笔记

文章目录 直线运动弹簧和简谐运动动能&#xff0c;势能&#xff0c;机械能动量动量守恒机械能守恒弹性碰撞和非弹性碰撞冲量 圆周运动匀速圆周运动转动惯量平行轴定理 角动量角动量守恒 英语 直线运动 弹簧和简谐运动 F s → − k x 1 → \overrightarrow{F_s}-k \overrighta…...

【论文+源码】基于Spring和Spring MVC的汉服文化宣传网站

为了实现一个基于Spring和Spring MVC的汉服文化宣传网站,我们需要创建一个简单的Web应用程序来展示汉服文化和相关信息。这个系统将包括以下几个部分: 数据库表设计:定义文章、用户和评论的相关表。实体类:表示数据库中的数据。DAO层接口及MyBatis映射文件:用于与数据库交…...

计算机的错误计算(一百九十九)

摘要 用大模型判断下面四个函数 有何关系&#xff1f;并计算它们在 x0.00024时的值&#xff0c;结果保留10位有效数字。两个大模型均认为它们是等价的。实际上&#xff0c;还有点瑕疵。关于计算函数值&#xff0c;大模型一只是纸上谈兵&#xff0c;没计算&#xff1b;大模型二…...

【AI日记】25.01.02 kaggle 比赛 3-1

【AI论文解读】【AI知识点】【AI小项目】【AI战略思考】【AI日记】 工作 参加&#xff1a;kaggle 比赛 Forecasting Sticker Sales时间&#xff1a;4 小时 读书 书名&#xff1a;秦制两千年时间&#xff1a;5 小时阅读原因&#xff1a;之前看过 《商君书》&#xff0c;对秦制…...