概述
一、源代码:
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:vim 4_8.c
1 #include "apue.h"
2 #include <fcntl.h>
3
4 int main(int argc, char *argv[])
5 {
6 if ( argc != 2 )
7 err_quit("Usage: access <pathname>");
8 if ( access(argv[1], R_OK) < 0 )
9 err_ret("access error");
10 else
11 printf("real user id has read permission of %sn",argv[1]);
12 if ( open(argv[1],O_RDONLY) < 0 )
13 err_ret("open error");
14 else
15 printf("open file %s successfullyn", argv[1]);
16
17 exit(0);
18
19 }
20
~
二、运行结果:
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:access error.c
real user id has read permission of error.c
open file error.c successfully
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:access /etc/passwd
real user id has read permission of /etc/passwd
open file /etc/passwd successfully
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:access /etc/shadow
access error: Permission denied
open error: Permission denied
<bldc:/home/tingbinz/apue.3e/SBSCODE/4>R*_*G:
最后
以上就是合适老虎为你收集整理的access and faccessat 按照实际用户Id和实际组ID进行文件权限测试的全部内容,希望文章能够帮你解决access and faccessat 按照实际用户Id和实际组ID进行文件权限测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复