BSD 2 development
[unix-history] / src / fleece.c
CommitLineData
dd30ce89
KS
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
14char *pwfile = "/etc/passwd";
15
16main(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
51gethome(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}