从上面的文件存取权限可以看出,root用户可以对其读写,root所在的root组可对其读,其他组用户只可对其读。现在我们更改这个文件的权限,让非root用户可对其修改。
edsionte@edsionte-laptop:/usr/include$ sudo chmod 777 error.h
[sudo] password for edsionte:
edsionte@edsionte-laptop:/usr/include$ ls -l error.h
-rwxrwxrwx 1 root root 2557 2010-06-23 12:11 error.h
修改好权限后,就可以用上面的方法对error.h文件进行修改并保存。
下面进行测试:
测试源码如下。
#include “errno.h”
#include “fcntl.h“
#include "unistd.h”
#include "stdlib.h“
#include "stdio.h”
#include ”sys/types.h“
#include “sys/stat.h”
#include ”string.h“
#include “error.h”
int main()
{
int fd;
if((fd=open("example_test.c",O_CREAT|O_EXCL,S_IRUSR|S_IWUSR))==-1)
{
my_err1(errno);
// my_err2("open",__LINE__,errno);
}
close(fd);
return 0;
}
}
首先测试my_err1,结果如下:
edsionte@edsionte-laptop:~/code$ ./my_error
error: File exists with errno: 17
然后将my_err1注释掉,测试my_err2,结果如下:
edsionte@edsionte-laptop:~/code$ ./my_error
error: line:17 open():File exists with errno:17
结果和前面介绍捕获函数时的测试结果一样。你以为现在就结束了吗?当然没有,我们要把error.h头文件的权限修改成原样。
edsionte@edsionte-laptop:/usr/include$ sudo chmod 644 error.h
[sudo] password for edsionte:
edsionte@edsionte-laptop:/usr/include$ ls -l error.h
-rw-r--r-- 1 root root 2557 2010-06-23 12:50 error.h
大功告成。
