cputimer: Initialize explicitly.
[dragonfly.git] / contrib / opie / libmissing / getusershell.c
blob885aa04ffa5f04f54361d3d0096d5dc4917edc8e
1 /* getusershell.c: minimal implementation of the getusershell() and
2 endusershell() library routines for systems that don't have them.
4 %%% portions-copyright-cmetz
5 Portions of this software are Copyright 1996 by Craig Metz, All Rights
6 Reserved. The Inner Net License Version 2 applies to these portions of
7 the software.
8 You should have received a copy of the license with this software. If
9 you didn't get a copy, you may request one from <license@inner.net>.
11 Portions of this software are Copyright 1995 by Randall Atkinson and Dan
12 McDonald, All Rights Reserved. All Rights under this copyright are assigned
13 to the U.S. Naval Research Laboratory (NRL). The NRL Copyright Notice and
14 License Agreement applies to this software.
16 History:
18 Modified by cmetz for OPIE 2.2. Use FUNCTION declaration et al.
19 Modified at NRL for OPIE 2.1. Remove trailing newlines from
20 /etc/shells entries. Fixed infinite loop. Fixed a bug
21 where second invocation on would fail.
22 Written at NRL for OPIE 2.0.
24 #include "opie_cfg.h"
25 #include <stdio.h>
26 #if HAVE_STRING_H
27 #include <string.h>
28 #endif /* HAVE_STRING_H */
29 #include "opie.h"
31 static FILE *fh = NULL;
32 static char *internal[] = {"/bin/sh", "/bin/csh", NULL};
33 static int i = 0;
34 static char buffer[1024];
36 char *getusershell FUNCTION_NOARGS
38 char *c;
40 if (!fh)
41 fh = fopen("/etc/shells", "r");
43 if (fh) {
44 if (fgets(buffer, sizeof(buffer), fh)) {
45 if (c = strchr(buffer, '\n'))
46 *c = 0;
47 return buffer;
48 } else {
49 fclose(fh);
50 return NULL;
52 } else {
53 if (internal[i])
54 return internal[i++];
55 else
56 return NULL;
60 VOIDRET endusershell FUNCTION_NOARGS
62 if (fh) {
63 fclose(fh);
64 fh = NULL;
66 i = 0;