fchmod
调用把fd引用的文件的权限位(文件模式)改为mode指定的八进制模式。
#include <sys/types.h>
#include <sys/stat.h>
int fchmod(int fd, mode_t mode)
该函数调用正确返回0,失败返回-1,并设置errno变量。
错误代码:errno
EBADF 参数fildes为无效的文件描述词
EPERM 进程的有效用户识别码与欲修改的文件所有者不同,而且也不具root权限
EROFS 欲写入权限的文件存在于只读文件系统内
EIO I/O存取错误
*/
范例:
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
int fd;
fd=open("a.txt",O_RDONLY);
int i=fchmod(fd,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
printf("the i is %d\n",i);
//chmod(fd);
close (fd);
}