编程参考 - C标准库中的errno定义

1,Linux系统
以GLibc作为C标准库代表,Linux作为操作系统代表,来确定errno的定义。
当使用C标准库的errno.h这个头文件时,其包含内容:
include/errno.h
#include <stdlib/errno.h>
// errno定义分情况:
// 1, 动态链接库
/* The dynamic linker uses its own private errno variable.
   All access to errno inside the dynamic linker is serialized,
   so a single (hidden) global variable is all it needs.  */
# define errno rtld_errno
// 2, libc
# define errno __libc_errno
// 3, 其他情况, 使用线程修饰符
# define errno errno /* For #ifndef errno tests. */
extern __thread int errno attribute_tls_model_ie;
// 函数
# define __set_errno(val) (errno = (val))  // GLibc库里面都用这个函数来设置errno
stdlib/errno.h
#include <bits/errno.h>
// 下面这个是GNU才有
/* The full and simple forms of the name with which the program was
   invoked.  These variables are set up automatically at startup based on
   the value of argv[0].  */
extern char *program_invocation_name;
extern char *program_invocation_short_name;
#include <bits/types/error_t.h>
bits/errno.h
// 这个是包含了Linux系统的头文件
# include <linux/errno.h> 
/* Older Linux headers do not define these constants.  */
# ifndef ENOTSUP
#  define ENOTSUP        EOPNOTSUPP
# endif
# ifndef ECANCELED
#  define ECANCELED        125
# endif
# ifndef EOWNERDEAD
#  define EOWNERDEAD        130
# endif
#ifndef ENOTRECOVERABLE
#  define ENOTRECOVERABLE    131
# endif
# ifndef ERFKILL
#  define ERFKILL        132
# endif
# ifndef EHWPOISON
#  define EHWPOISON        133
# endif
#endif /* bits/errno.h.  */
bits/types/error_t.h
typedef int error_t;
Linux系统的errno.h包含内容:
linux/errno.h
#include <uapi/linux/errno.h>
/*
* These should never be seen by user programs.  To return one of ERESTART*
* codes, signal_pending() MUST be set.  Note that ptrace can observe these
* at syscall exit tracing, but they will never be left for the debugged user
* process to see.
*/
#define ERESTARTSYS    512
#define ERESTARTNOINTR    513
#define ERESTARTNOHAND    514    /* restart if no handler.. */
#define ENOIOCTLCMD    515    /* No ioctl command */
#define ERESTART_RESTARTBLOCK 516 /* restart by calling sys_restart_syscall */
#define EPROBE_DEFER    517    /* Driver requests probe retry */
#define EOPENSTALE    518    /* open found a stale dentry */
#define ENOPARAM    519    /* Parameter not supported */
/* Defined for the NFSv3 protocol */
#define EBADHANDLE    521    /* Illegal NFS file handle */
#define ENOTSYNC    522    /* Update synchronization mismatch */
#define EBADCOOKIE    523    /* Cookie is stale */
#define ENOTSUPP    524    /* Operation is not supported */
#define ETOOSMALL    525    /* Buffer or request is too small */
#define ESERVERFAULT    526    /* An untranslatable error occurred */
#define EBADTYPE    527    /* Type not supported by server */
#define EJUKEBOX    528    /* Request initiated, but will not complete before timeout */
#define EIOCBQUEUED    529    /* iocb queued, will get completion event */
#define ERECALLCONFLICT    530    /* conflict with recalled state */
#define ENOGRACE    531    /* NFS file lock reclaim refused */
#endif
uapi/linux/errno.h
#include <asm/errno.h>
asm/errno.h
#include <asm-generic/errno.h>
asm-generic/errno.h
#include <asm-generic/errno-base.h>
#define    EDEADLK        35    /* Resource deadlock would occur */
#define    ENAMETOOLONG    36    /* File name too long */
#define    ENOLCK        37    /* No record locks available */
/*
* This error code is special: arch syscall entry code will return
* -ENOSYS if users try to call a syscall that doesn't exist.  To keep
* failures of syscalls that really do exist distinguishable from
* failures due to attempts to use a nonexistent syscall, syscall
* implementations should refrain from returning -ENOSYS.
*/
#define    ENOSYS        38    /* Invalid system call number */
#define    ENOTEMPTY    39    /* Directory not empty */
#define    ELOOP        40    /* Too many symbolic links encountered */
#define    EWOULDBLOCK    EAGAIN    /* Operation would block */
#define    ENOMSG        42    /* No message of desired type */
#define    EIDRM        43    /* Identifier removed */
#define    ECHRNG        44    /* Channel number out of range */
#define    EL2NSYNC    45    /* Level 2 not synchronized */
#define    EL3HLT        46    /* Level 3 halted */
#define    EL3RST        47    /* Level 3 reset */
#define    ELNRNG        48    /* Link number out of range */
#define    EUNATCH        49    /* Protocol driver not attached */
#define    ENOCSI        50    /* No CSI structure available */
#define    EL2HLT        51    /* Level 2 halted */
#define    EBADE        52    /* Invalid exchange */
#define    EBADR        53    /* Invalid request descriptor */
#define    EXFULL        54    /* Exchange full */
#define    ENOANO        55    /* No anode */
#define    EBADRQC        56    /* Invalid request code */
#define    EBADSLT        57    /* Invalid slot */
#define    EDEADLOCK    EDEADLK
#define    EBFONT        59    /* Bad font file format */
#define    ENOSTR        60    /* Device not a stream */
#define    ENODATA        61    /* No data available */
#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 */
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夜流冰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值