fchmod.c 465 字节
Newer Older
R
Rich Felker 已提交
1
#include <sys/stat.h>
2
#include <errno.h>
3
#include <fcntl.h>
R
Rich Felker 已提交
4 5
#include "syscall.h"

6 7
void __procfdname(char *, unsigned);

R
Rich Felker 已提交
8 9
int fchmod(int fd, mode_t mode)
{
10
	int ret = __syscall(SYS_fchmod, fd, mode);
11 12
	if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0)
		return __syscall_ret(ret);
13 14 15

	char buf[15+3*sizeof(int)];
	__procfdname(buf, fd);
16
#ifdef SYS_chmod
17
	return syscall(SYS_chmod, buf, mode);
18 19 20
#else
	return syscall(SYS_fchmodat, AT_FDCWD, buf, mode);
#endif
R
Rich Felker 已提交
21
}