File:  [MW Coherent from dump] / coherent / d / bin / chown.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:39 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/*
 * Change the owner of specified files.
 */

#include <stdio.h>
#include <sys/stat.h>
#include <pwd.h>

main(argc, argv)
char *argv[];
{
	register struct passwd *pwp;
	register int c;
	register short owner, group;
	struct stat sb;
	register short status = 0;

	if (argc < 3)
		usage();
	if ((c = *argv[1])>='0' && c<='9')
		owner = atoi(argv[1]);
	else {
		if ((pwp = getpwnam(argv[1])) == NULL)
			cherr("Bad username `%s'\n", argv[1]);
		owner = pwp->pw_uid;
	}
	for (c = 2; c < argc; c++) {
		group = 0;
		if (stat(argv[c], &sb) >= 0)
			group = sb.st_gid;
		if (chown(argv[c], owner, group) < 0) {
			perror(argv[c]);
			status = 2;
		}
	}
	exit (status);
}

usage()
{
	fprintf(stderr, "Usage: chown owner file ...\n");
	exit(1);
}

/* VARARGS */
cherr(x)
{
	fprintf(stderr, "chown: %r", &x);
	exit(2);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.