#include <sys/types.h> #include <sys/stat.h> int fchmod(int fileDescriptor, mode_t mode);
fchmod
changes the file permission flags for the directory
or file specified by fileDescriptor
. The mode
argument
can be any combination of the following symbols, which are defined in
<stat.h>
:
S_ISUID
exec
function, the user ID of the process is also set for
execution.
S_ISGID
exec
function, the group ID of the process is also
set for execution.
S_ISVTX
S_IRUSR
S_IWUSR
S_IXUSR
S_IRWXU
S_IRGRP
S_IWGRP
S_IXGRP
S_IRWXG
S_IROTH
S_IWOTH
S_IXOTH
S_IRWXO
fchmod
returns 0 if it is successful. If unsuccessful, a
- 1 is returned.
#include <sys/types.h> #include <sys/stat.h> int fchexec(int fd) { struct stat stat_data; mode_t newmode; int rc; rc = fstat(fd, &stat_data); if (rc != 0) { perror("fstat failure"); return -1; } newmode = stat_data.st_mode; if (newmode & S_IRUSR) newmode |= S_IXUSR; if (newmode & S_IRGRP) newmode |= S_IXGRP; if (newmode & S_IROTH) newmode |= S_IXOTH; /* If the mode bits changed, make them effective. */ if (newmode != stat_data.st_mode) { rc = fchmod(fd, newmode); if (rc != 0) perror("fchmod failure"); return rc; } return(0); /* No change was necessary. */ }
chmod
, chown
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.