1: /*
   2:  * chown uid file ...
   3:  */
   4: 
   5: #include <stdio.h>
   6: #include <ctype.h>
   7: #include <sys/types.h>
   8: #include <sys/stat.h>
   9: #include <pwd.h>
  10: 
  11: struct  passwd  *pwd,*getpwnam();
  12: struct  stat    stbuf;
  13: int uid;
  14: int status;
  15: 
  16: main(argc, argv)
  17: char *argv[];
  18: {
  19:     register c;
  20: 
  21:     if(argc < 3) {
  22:         printf("usage: chown uid file ...\n");
  23:         exit(4);
  24:     }
  25:     if(isnumber(argv[1])) {
  26:         uid = atoi(argv[1]);
  27:         goto cho;
  28:     }
  29:     if((pwd=getpwnam(argv[1])) == NULL) {
  30:         printf("unknown user id: %s\n",argv[1]);
  31:         exit(4);
  32:     }
  33:     uid = pwd->pw_uid;
  34: 
  35: cho:
  36:     for(c=2; c<argc; c++) {
  37:         stat(argv[c], &stbuf);
  38:         if(chown(argv[c], uid, stbuf.st_gid) < 0) {
  39:             perror(argv[c]);
  40:             status = 1;
  41:         }
  42:     }
  43:     exit(status);
  44: }
  45: 
  46: isnumber(s)
  47: char *s;
  48: {
  49:     register c;
  50: 
  51:     while(c = *s++)
  52:         if(!isdigit(c))
  53:             return(0);
  54:     return(1);
  55: }

Defined functions

isnumber defined in line 46; used 1 times
  • in line 25
main defined in line 16; never used

Defined variables

pwd defined in line 11; used 2 times
status defined in line 14; used 2 times
stbuf defined in line 12; used 2 times
uid defined in line 13; used 3 times
Last modified: 1979-01-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 577
Valid CSS Valid XHTML 1.0 Strict