xref: /haiku/src/system/libroot/posix/sys/chmod.c (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
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 <errno_private.h>
13 #include <syscalls.h>
14 #include <syscall_utils.h>
15 
16 
17 int
18 chmod(const char *path, mode_t mode)
19 {
20 	struct stat stat;
21 	status_t status;
22 
23 	stat.st_mode = mode;
24 	status = _kern_write_stat(AT_FDCWD, path, true, &stat, sizeof(struct stat),
25 		B_STAT_MODE);
26 
27 	RETURN_AND_SET_ERRNO(status);
28 }
29 
30 
31 int
32 fchmod(int fd, mode_t mode)
33 {
34 	struct stat stat;
35 	status_t status;
36 
37 	stat.st_mode = mode;
38 	status = _kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat),
39 		B_STAT_MODE);
40 
41 	RETURN_AND_SET_ERRNO(status);
42 }
43 
44 
45 int
46 fchmodat(int fd, const char* path, mode_t mode, int flag)
47 {
48 	struct stat stat;
49 	status_t status;
50 
51 	stat.st_mode = mode;
52 	status = _kern_write_stat(fd, path, (flag & AT_SYMLINK_NOFOLLOW) == 0, &stat,
53 		sizeof(struct stat), B_STAT_MODE);
54 
55 	RETURN_AND_SET_ERRNO(status);
56 }
57