打印文件操作错误信息
在进行文件操作是,会遇到权限不足、找不到文件等错误,可以在程序中设置错误捕捉语句并显示错误。错误捕捉和错误输出使用用错误号和streero实现。
函数原型 :
char *streeor(int errnum);
头文件
#include<string.h>
#include<errno.h>
打印文件操作的错误码机器信息:
#include <stdio.h>
#include <string.h>
#include <errno.h>
int main(void)
{
int i = 0;
for(i=0 ; i < 34 ; i++)
{
printf("Errno:%d ", i);
printf("Message:%s
" , strerror(i));
}
return 0;
}
[Linux@centos-64-min exercise]$ ./error
Errno:0 Message:Success
Errno:1 Message:Operation not permitted
Errno:2 Message:No such file or directory
Errno:3 Message:No such process
Errno:4 Message:Interrupted system call
Errno:5 Message:Input/output error
Errno:6 Message:No such device or address
Errno:7 Message:Argument list too long
Errno:8 Message:Exec format error
Errno:9 Message:Bad file descriptor
Errno:10 Message:No child processes
Errno:11 Message:Resource temporarily unavailable
Errno:12 Message:Cannot allocate memory
Errno:13 Message:Permission denied
Errno:14 Message:Bad address
Errno:15 Message:Block device required
Errno:16 Message:Device or resource busy
Errno:17 Message:File exists
Errno:18 Message:Invalid cross-device link
Errno:19 Message:No such device
Errno:20 Message:Not a directory
Errno:21 Message:Is a directory
Errno:22 Message:Invalid argument
Errno:23 Message:Too many open files in system
Errno:24 Message:Too many open files
Errno:25 Message:Inappropriate ioctl for device
Errno:26 Message:Text file busy
Errno:27 Message:File too large
Errno:28 Message:No space left on device
Errno:29 Message:Illegal seek
Errno:30 Message:Read-only file system
Errno:31 Message:Too many links
Errno:32 Message:Broken pipe
Errno:33 Message:Numerical argument out of domain