最近在网络编程使用的过程中,发现errno会经常使用。因此决定在此做个留用,以备以后使用。。。
虽然errno是非线程安全的,但是可以通过几种机制保证其安全。。
最近在使用的过程中获得了errno,程序无法执行,也不知道如何解决问题。因此,理解每一个返回的errno整数值的含义是很重要的。。
这个我们可以通过strerror函数来实现。。
strerror(返回整数errno对应的错误原因的描述字符串)
所需头文件: #include函数声明: char * strerror(int errnum);
输入: 整数errno
输出: 返回描述错误原因的字符串指针
功能: 用来依参数errnum 的错误代码来查询其错误原因的描述字符串,然后将该字符串指针返回。
示例:
#include #include
#define NUM 150
int main(void)
{
int i;
for ( i=0; i{
printf( "%d:%s\n", i, strerror(i) );
}
return 0;
}
运行结果:
0:Success
1:Operation not permitted
2:No such file or directory
3:No such process
4:Interrupted system call
5:Input/output error
6:No such device or address
7:Argument list too long
8:Exec format error
9:Bad file descriptor
10:No child processes
11:Resource temporarily unavailable
12:Cannot allocate memory
13:Permission denied
14:Bad address
15:Block device required
16:Device or resource busy
17:File exists
18:Invalid cross-device link
19:No such device
20:Not a directory
21:Is a directory
22:Invalid argument
23:Too many open files in system
24:Too many open files
25:Inappropriate ioctl for device
26:Text file busy
27:File too large
28:No space left on device
29:Illega