8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / tools / cscope-fast / logdir.c
blobeb633b2e81961c42ec50e44f9ec4fade0e49612f
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
22 /* Copyright (c) 1988 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1999 by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 * logdir()
36 * This routine does not use the getpwent(3) library routine
37 * because the latter uses the stdio package. The allocation of
38 * storage in this package destroys the integrity of the shell's
39 * storage allocation.
42 #include <fcntl.h> /* O_RDONLY */
43 #include <stdlib.h>
44 #include <unistd.h>
45 #include <string.h>
47 #define BUFSIZ 160
49 static char line[BUFSIZ+1];
51 static char *
52 passwdfield(char *p)
54 while (*p && *p != ':')
55 ++p;
56 if (*p)
57 *p++ = 0;
58 return (p);
61 char *
62 logdir(char *name)
64 char *p;
65 int i, j;
66 int pwf;
68 /* attempt to open the password file */
69 if ((pwf = open("/etc/passwd", O_RDONLY)) == -1)
70 return (0);
72 /* find the matching password entry */
73 do {
74 /* get the next line in the password file */
75 i = read(pwf, line, BUFSIZ);
76 for (j = 0; j < i; j++)
77 if (line[j] == '\n')
78 break;
79 /* return a null pointer if the whole file has been read */
80 if (j >= i)
81 return (0);
82 line[++j] = 0; /* terminate the line */
83 /* point at the next line */
84 (void) lseek(pwf, (long)(j - i), 1);
85 p = passwdfield(line); /* get the logname */
86 } while (*name != *line || /* fast pretest */
87 strcmp(name, line) != 0);
88 (void) close(pwf);
90 /* skip the intervening fields */
91 p = passwdfield(p);
92 p = passwdfield(p);
93 p = passwdfield(p);
94 p = passwdfield(p);
96 /* return the login directory */
97 (void) passwdfield(p);
98 return (p);