1 /* 2 * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <errno.h> 8 #include <sys/stat.h> 9 10 #include <NodeMonitor.h> 11 12 #include <syscalls.h> 13 #include <syscall_utils.h> 14 15 16 int 17 chmod(const char *path, mode_t mode) 18 { 19 struct stat stat; 20 status_t status; 21 22 stat.st_mode = mode; 23 status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), 24 B_STAT_MODE); 25 26 RETURN_AND_SET_ERRNO(status); 27 } 28 29 30 int 31 fchmod(int fd, mode_t mode) 32 { 33 struct stat stat; 34 status_t status; 35 36 stat.st_mode = mode; 37 status = _kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat), 38 B_STAT_MODE); 39 40 RETURN_AND_SET_ERRNO(status); 41 } 42 43 44 int 45 fchmodat(int fd, const char* path, mode_t mode, int flag) 46 { 47 struct stat stat; 48 status_t status; 49 50 stat.st_mode = mode; 51 status = _kern_write_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, &stat, 52 sizeof(struct stat), B_STAT_MODE); 53 54 RETURN_AND_SET_ERRNO(status); 55 } 56