Added a missing comma in example code (fix from o1i).
[AROS.git] / compiler / posixc / chmod.c
blobdf6b80a5036263156a27f80f2cdf7dde450d2620
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <dos/dos.h>
7 #include <proto/dos.h>
9 #include <errno.h>
10 #include <sys/types.h>
12 #include "__upath.h"
14 ULONG prot_u2a(mode_t protect);
16 /*****************************************************************************
18 NAME */
19 #include <sys/stat.h>
21 int chmod(
23 /* SYNOPSIS */
24 const char *path,
25 mode_t mode)
27 /* FUNCTION
28 Change permission bits of a specified file.
30 INPUTS
31 path - Pathname of the file
32 mode - Bit mask created by ORing zero or more of the following
33 permission bit masks:
35 S_ISUID - set user id on execution
36 S_ISGID - set group id on execution
37 S_ISVTX - sticky bit (restricted deletion flag)
38 S_IRUSR - allow owner to read
39 S_IWUSR - allow owner to write
40 S_IXUSR - allow owner to execute/search directory
41 S_IRGRP - allow group to read
42 S_IWGRP - allow group to write
43 S_IXGRP - allow group to execute/search directory
44 S_IROTH - allow others to read
45 S_IWOTH - allow others to write
46 S_IXOTH - allow others to execute/search directory
48 RESULT
49 0 on success and -1 on error. If an error occurred, the global
50 variable errno is set.
52 NOTES
54 EXAMPLE
56 BUGS
57 S_ISUID and S_ISGID are silently ignored.
59 SEE ALSO
60 fchmod()
62 INTERNALS
63 Permission bit masks are converted to their respective dos.library
64 counterparts:
66 S_ISVTX to FIBF_SCRIPT
67 !S_IRUSR to FIBF_READ
68 !S_IWUSR to FIBF_WRITE
69 !S_IXUSR to FIBF_EXECUTE
70 S_IRGRP to FIBF_GRP_READ
71 S_IWGRP to FIBF_GRP_WRITE
72 S_IXGRP to FIBF_GRP_EXECUTE
73 S_IROTH to FIBF_OTR_READ
74 S_IWOTH to FIBF_OTR_WRITE
75 S_IXOTH to FIBF_OTR_EXECUTE
77 ******************************************************************************/
79 if (!path) /*safety check */
81 errno = EFAULT;
82 return -1;
85 path = __path_u2a(path);
86 if (path == NULL)
87 return -1;
89 if (!SetProtection(path, prot_u2a(mode)))
91 errno = __stdc_ioerr2errno(IoErr());
92 return -1;
95 return 0;
99 /* taken from emul_handler */
100 ULONG prot_u2a(mode_t protect)
102 ULONG aprot = 0;
104 /* The following three (AROS) flags are low-active! */
105 if (!(protect & S_IRUSR))
106 aprot |= FIBF_READ;
107 if (!(protect & S_IWUSR))
108 aprot |= FIBF_WRITE;
109 if (!(protect & S_IXUSR))
110 aprot |= FIBF_EXECUTE;
112 /* The following flags are high-active again. */
113 if ((protect & S_IRGRP))
114 aprot |= FIBF_GRP_READ;
115 if ((protect & S_IWGRP))
116 aprot |= FIBF_GRP_WRITE;
117 if ((protect & S_IXGRP))
118 aprot |= FIBF_GRP_EXECUTE;
119 if ((protect & S_IROTH))
120 aprot |= FIBF_OTR_READ;
121 if ((protect & S_IWOTH))
122 aprot |= FIBF_OTR_WRITE;
123 if ((protect & S_IXOTH))
124 aprot |= FIBF_OTR_EXECUTE;
126 if ((protect & S_ISVTX))
127 aprot |= FIBF_SCRIPT;
129 return aprot;