Annotation of coherent/d/bin/chown.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Change the owner of specified files.
                      3:  */
                      4: 
                      5: #include <stdio.h>
                      6: #include <sys/stat.h>
                      7: #include <pwd.h>
                      8: 
                      9: main(argc, argv)
                     10: char *argv[];
                     11: {
                     12:        register struct passwd *pwp;
                     13:        register int c;
                     14:        register short owner, group;
                     15:        struct stat sb;
                     16:        register short status = 0;
                     17: 
                     18:        if (argc < 3)
                     19:                usage();
                     20:        if ((c = *argv[1])>='0' && c<='9')
                     21:                owner = atoi(argv[1]);
                     22:        else {
                     23:                if ((pwp = getpwnam(argv[1])) == NULL)
                     24:                        cherr("Bad username `%s'\n", argv[1]);
                     25:                owner = pwp->pw_uid;
                     26:        }
                     27:        for (c = 2; c < argc; c++) {
                     28:                group = 0;
                     29:                if (stat(argv[c], &sb) >= 0)
                     30:                        group = sb.st_gid;
                     31:                if (chown(argv[c], owner, group) < 0) {
                     32:                        perror(argv[c]);
                     33:                        status = 2;
                     34:                }
                     35:        }
                     36:        exit (status);
                     37: }
                     38: 
                     39: usage()
                     40: {
                     41:        fprintf(stderr, "Usage: chown owner file ...\n");
                     42:        exit(1);
                     43: }
                     44: 
                     45: /* VARARGS */
                     46: cherr(x)
                     47: {
                     48:        fprintf(stderr, "chown: %r", &x);
                     49:        exit(2);
                     50: }

unix.superglobalmegacorp.com

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