![]() Chapter Contents |
![]() Previous |
![]() Next |
| chown |
| Portability: | POSIX.1 conformaing, UNIX compatible |
| SYNOPSIS | |
| DESCRIPTION | |
| RETURN VALUE | |
| EXAMPLE | |
| RELATED FUNCTIONS |
| SYNOPSIS |
#include <sys/types.h> #include <unistd.h> int chown(const char *pathname, uid_t owner, gid_t group);
| DESCRIPTION |
chown changes
the owner or owning group of a file. It can be used with either regular files
or special files, such as directories or FIFO files. pathname is the name of the file. owner
is the user ID. group is the group ID.
UNIX System Services implements a restricted chown
for all files. A call to chown can succeed
in only one of two ways:
chown, and
the group argument is the effective group ID or one of the user's supplementary
ID's.
If the S_IXUSR, S_IXGRP, or S_IXOTH bit is set in the file permissions,
chown clears the S_ISUID and S_ISGID bits of the permissions.
| RETURN VALUE |
chown returns 0 if successful and a -1 if
not successful.
| EXAMPLE |
The following example illustrates the use of chown to change a file's owner and group:
#include #include #include #include
main(int argc, char *argv[])
{
struct group *billing;
int rc;
billing = getgrnam("BILLING");
if (!billing) {
perror("getgrnam error");
abort();
}
if (argc <= 1) {
printf("No file name specified.n");
exit(EXIT_FAILURE);
}
rc = chown(argv[1], geteuid(), billing->gr_gid);
if (rc == 0) {
printf("Ownership of %s assigned to BILLING.n", argv[1]);
exit(EXIT_SUCCESS);
}
else {
perror("chown error");
abort();
}
}
| RELATED FUNCTIONS |
chmod, fchown
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.