arch/m68k-amiga: Define the gcc symbol 'start' instead of using .bss
[AROS.git] / compiler / clib / chmod.c
blob5ce868edc675b776d74f42bd251432706e9b603c
1 /*
2 Copyright © 1995-2001, 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 "__errno.h"
13 #include "__upath.h"
15 ULONG prot_u2a(mode_t protect);
17 /*****************************************************************************
19 NAME */
20 #include <sys/stat.h>
22 int chmod(
24 /* SYNOPSIS */
25 const char *path,
26 mode_t mode)
28 /* FUNCTION
29 Change permission bits of a specified file.
31 INPUTS
32 path - Pathname of the file
33 mode - Bit mask created by ORing zero or more of the following
34 permission bit masks:
36 S_ISUID - set user id on execution
37 S_ISGID - set group id on execution
38 S_ISVTX - sticky bit (restricted deletion flag)
39 S_IRUSR - allow owner to read
40 S_IWUSR - allow owner to write
41 S_IXUSR - allow owner to execute/search directory
42 S_IRGRP - allow group to read
43 S_IWGRP - allow group to write
44 S_IXGRP - allow group to execute/search directory
45 S_IROTH - allow others to read
46 S_IWOTH - allow others to write
47 S_IXOTH - allow others to execute/search directory
49 RESULT
50 0 on success and -1 on error. If an error occurred, the global
51 variable errno is set.
53 NOTES
55 EXAMPLE
57 BUGS
58 S_ISUID and S_ISGID are silently ignored.
60 SEE ALSO
61 fchmod()
63 INTERNALS
64 Permission bit masks are converted to their respective dos.library
65 counterparts:
67 S_ISVTX to FIBF_SCRIPT
68 !S_IRUSR to FIBF_READ
69 !S_IWUSR to FIBF_WRITE
70 !S_IXUSR to FIBF_EXECUTE
71 S_IRGRP to FIBF_GRP_READ
72 S_IWGRP to FIBF_GRP_WRITE
73 S_IXGRP to FIBF_GRP_EXECUTE
74 S_IROTH to FIBF_OTR_READ
75 S_IWOTH to FIBF_OTR_WRITE
76 S_IXOTH to FIBF_OTR_EXECUTE
78 ******************************************************************************/
80 if (!path) /*safety check */
82 errno = EFAULT;
83 return -1;
86 path = __path_u2a(path);
87 if (path == NULL)
88 return -1;
90 if (!SetProtection(path, prot_u2a(mode)))
92 errno = IoErr2errno(IoErr());
93 return -1;
96 return 0;
100 /* taken from emul_handler */
101 ULONG prot_u2a(mode_t protect)
103 ULONG aprot = 0;
105 /* The following three (AROS) flags are low-active! */
106 if (!(protect & S_IRUSR))
107 aprot |= FIBF_READ;
108 if (!(protect & S_IWUSR))
109 aprot |= FIBF_WRITE;
110 if (!(protect & S_IXUSR))
111 aprot |= FIBF_EXECUTE;
113 /* The following flags are high-active again. */
114 if ((protect & S_IRGRP))
115 aprot |= FIBF_GRP_READ;
116 if ((protect & S_IWGRP))
117 aprot |= FIBF_GRP_WRITE;
118 if ((protect & S_IXGRP))
119 aprot |= FIBF_GRP_EXECUTE;
120 if ((protect & S_IROTH))
121 aprot |= FIBF_OTR_READ;
122 if ((protect & S_IWOTH))
123 aprot |= FIBF_OTR_WRITE;
124 if ((protect & S_IXOTH))
125 aprot |= FIBF_OTR_EXECUTE;
127 if ((protect & S_ISVTX))
128 aprot |= FIBF_SCRIPT;
130 return aprot;