程序:
#include<stdio.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<fcntl.h>
void main()
{
int fd=open("b.txt",O_RDONLY);
fchmod(fd,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH);
}
输出:
$ ls -l b.txt
----r----- 1 mohanraj mohanraj 0 Sep 12 15:09 b.txt
$ ./a.out
$ ls -l b.txt
----r----- 1 mohanraj mohanraj 0 Sep 12 15:09 b.txt
$
对于上述程序,我的期望输出是将b.txt的权限设置为"rw_rw_r__",但是它仍然保持旧的权限。为什么会这样?这段代码有任何错误吗?
void main()
... - 3442fchmod
返回的值,如果失败则检查errno
。 - Some programmer dude