Professional Documents
Culture Documents
1 2
5 6
7 8
9 10
21 22
23 24
33
S_IXOTH -- other-execute 34
Example: umask
#include
#include
<stdio.h>
<sys/types.h>
chmod and fchmod
#include <sys/stat.h>
#include <fcntl.h>
{
perror("creat error for foo");
Change permissions of a file.
exit(1);
}
The mode of the file given by path or referenced by fd is
changed.
umask( S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH );
if( creat( "bar",
S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) < 0 )
mode is specified by OR’ing the following.
{
perror("creat error for bar");
S_I{R,W,X}{USR,GRP,OTH} (basic permissions)
exit(1); S_ISUID, S_ISGID, S_ISVTX (special bits)
}
exit(0); Effective uid of the process must be zero (superuser) or
}
must match the owner of the file.
{saffron:maria:68} ls -ltra foo bar
-rw-rw-rw- 1 dkl faculty 0 Apr 1 20:35 foo
On success, zero is returned. On error, -1 is returned.
-rw------- 1 dkl faculty 0 Apr 1 20:35 bar 39 40