1: /* Copyright (c) 1979 Regents of the University of California */
   2: #include <retrofit.h>
   3: #include <stdio.h>
   4: #include <sys/types.h>
   5: #include <sys/stat.h>
   6: 
   7: /*
   8:  * Look for a particular file name in everyone's home directory.
   9:  *
  10:  * Syntax: fleece name
  11:  * Author: Kurt Shoens (UCB) 1/11/79
  12:  */
  13: 
  14: char    *pwfile =   "/etc/passwd";
  15: 
  16: main(argc, argv)
  17:     char **argv;
  18: {
  19:     char namebuf[BUFSIZ], home[BUFSIZ], word[BUFSIZ];
  20:     register char *cp;
  21:     struct stat sbuf;
  22:     extern char _sobuf[];
  23: 
  24:     if (argc < 2) {
  25:         fprintf(stderr, "Usage: %s name ...\n", *argv);
  26:         exit(1);
  27:     }
  28:     setbuf(stdout, _sobuf);
  29:     strcpy(word, argv[1]);
  30:     if (freopen(pwfile, "r", stdin) == NULL) {
  31:         perror(pwfile);
  32:         exit(1);
  33:     }
  34:     while (gets(namebuf) != NULL) {
  35:         gethome(namebuf, home);
  36:         cp = home + strlen(home);
  37:         if (cp[-1] != '/')
  38:             *cp++ = '/';
  39:         strcpy(cp, word);
  40:         if (stat(home, &sbuf) >= 0)
  41:             puts(home);
  42:     }
  43:     exit(0);
  44: }
  45: 
  46: /*
  47:  * Find from the given passwd line the user's home directory
  48:  * and copy right.
  49:  */
  50: 
  51: gethome(pwline, home)
  52:     char pwline[], home[];
  53: {
  54:     register char *cp, *cp2;
  55:     register int c;
  56: 
  57:     for (cp = pwline, c = 0; c < 5 && *cp; c += *cp++ == ':')
  58:         ;
  59:     for (cp2 = home; *cp && *cp != ':'; *cp2++ = *cp++)
  60:         ;
  61:     *cp2 = 0;
  62: }

Defined functions

gethome defined in line 51; used 1 times
  • in line 35
main defined in line 16; never used

Defined variables

pwfile defined in line 14; used 2 times
Last modified: 1979-05-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 788
Valid CSS Valid XHTML 1.0 Strict