![]() Chapter Contents |
![]() Previous |
![]() Next |
| fchmod |
| Portability: | POSIX.1 conforming |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| EXAMPLE | |
| RELATED FUNCTIONS | |
| SEE ALSO |
| SYNOPSIS |
#include <sys/types.h> #include <sys/stat.h> int fchmod(int fileDescriptor, mode_t mode);
| DESCRIPTION |
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>
:
| RETURN VALUE |
fchmod
returns 0 if it is successful. If unsuccessful, a -1 is returned.
| EXAMPLE |
#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. */
}
| RELATED FUNCTIONS |
| SEE ALSO |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.