errno错误码列举

        errno,int变量,表示系统最近一次错误码。

        当系统调用和一些库函数发生错误时,会给errno赋值,以指示哪里出了问题。

目录

errno值列表

errno值获取示例


  • errno值列表

        <errno.h>头文件定义了errno的一些值,部分如下。注意,不同的Unix或Linux系统,每个宏的数值可能不同,名称和含义大体一致。

errno

数值

说明

EPERM  

Operation not permitted                

操作不允许

ENOENT 

No such file or directory              

没有该文件或目录

ESRCH  

No such process                        

没有该进程

EINTR  

Interrupted system call                

中断的系统调用

EIO    

Input/output error                     

输入/输出错误

ENXIO  

No such device or address              

没有该设备或地址

E2BIG  

Argument list too long                 

参数列表太长

ENOEXEC

Exec format error                      

执行文件格式错误

EBADF  

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           

对设备不合适的ioctl操作

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     

符号链接层次太多

EWOULDBLOCK

11

Operation would block

操作会阻塞

ENOMSG      

42

No message of desired type            

没有所需类型的消息

EIDRM       

43

Identifier removed                    

标识符删除

ECHRNG      

44

Channel number out of range           

频道号超出范围

EL2NSYNC    

45

Level 2 not synchronized              

2级不同步

EL3HLT      

46

Level 3 halted                        

3级暂停

EL3RST      

47

Level 3 reset                         

3级复位

ELNRNG      

48

Link number out of range              

链路号超出范围

EUNATCH     

49

Protocol driver not attached          

未附加协议驱动程序

ENOCSI      

50

No CSI structure available            

无CSI结构

EL2HLT      

51

Level 2 halted                        

2级暂停

EBADE       

52

Invalid exchange                      

无效交换

EBADR       

53

Invalid request descriptor            

无效请求描述符

EXFULL      

54

Exchange full                         

交换已满

ENOANO      

55

No anode                              

文件系统的inode表已满

EBADRQC     

56

Invalid request code                  

无效请求码

EBADSLT     

57

Invalid slot                          

无效的位置

EDEADLOCK   

58

File locking deadlock error            

文件锁定死锁错误

EBFONT

59

Bad font file format

错误的字体文件格式

ENOSTR

60

Device not a stream

不是流设备

  • errno值获取示例
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

int main(int argc, char *argv[])
{
    int fd;

    fd = open("./test.txt", O_RDONLY);
    if (fd == -1)
	{
        printf("open file failed! err: %d, %s\n", errno, strerror(errno));
		return -1;
    }
    close(fd);
	return 0;
}

执行输出:

  • 11
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值