Mercurial > hg > octave-kai > gnulib-hg
annotate lib/getusershell.c @ 6927:fa896bb33133
* lib/memcasecmp.c: Include <limits.h>.
(memcasecmp): Don't assume UCHAR_MAX <= INT_MAX.
* lib/strtod.c (strtod): Don't assume isspace works on negative chars.
Don't assume isdigit succeeds only on '0' through '9'.
* lib/exclude.c (IN_CTYPE_DOMAIN, is_space): Remove; no longer needed.
All uses of is_space replaced by isspace.
* lib/fnmatch.c (ISASCII): Remove; no longer needed. All uses removed.
(ISPRINT, ISDIGIT, ISALNUM, ISALPHA, ISCNTRL, ISLOWER, ISPUNCT):
(ISSPACE, ISUPPER, ISXDIGIT): Remove; no longer needed. All uses
replaced by isprint etc.
* lib/getdate.y (IN_CTYPE_DOMAIN, ISSPACE, ISALPHA, ISLOWER): Likewise.
* lib/getusershell.c (IN_CTYPE_DOMAIN, ISSPACE): Likewise.
* lib/memcasecmp.c (IN_CTYPE_DOMAIN, ISLOWER, TOUPPER): Likewise.
* lib/strtod.c (IN_CTYPE_DOMAIN, ISSPACE, ISDIGIT, TOLOWER): Likewise.
* lib/strtol.c (IN_CTYPE_DOMAIN): Likewise.
* lib/xstrtol.c (IN_CTYPE_DOMAIN, ISSPACE): Likewise.
* m4/xstrtol.m4 (gl_PREREQ_XSTRTOL): Use AC_CHECK_DECLS_ONCE
rather than AC_CHECK_DECLS for strtoimax and strtoumax.
* m4/getusershell.m4 (gl_PREREQ_GETUSERSHELL): Remove; no longer needed.
All uses removed.
* m4/strtol.m4 (gl_PREREQ_STRTOL): Likewise.
* m4/strtoul.m4 (gl_PREREQ_STRTOUL): Likewise.
* m4/exclude.m4 (gl_EXCLUDE): Don't check for isascii; no longer needed.
* m4/getdate.m4 (gl_GETDATE): Likewise.
* m4/getusershell.m4 (gl_PREREQ_GETUSERSHELL): Likewise.
* m4/memcasecmp.m4 (gl_MEMCASECMP): Likewise.
* m4/strtod.m4 (gl_FUNC_STRTOD): Likewise.
* m4/strtol.m4 (gl_PREREQ_STRTOL): Likewise.
* m4/strtoul.m4 (gl_PREREQ_STRTOUL): Likewise.
* m4/xstrtol.m4 (gl_PREREQ_XSTRTOL): Likewise.
* m4/exclude.m4 (gl_EXCLUDE): Don't require AC_C_INLINE; no longer
needed.
* m4/calloc.m4 (_AC_FUNC_CALLOC_IF): Don't require AC_HEADER_STDC;
no longer needed.
* m4/exclude.m4 (gl_EXCLUDE): Likewise.
* m4/getdate.m4 (gl_GETDATE): Likewise.
* m4/getusershell.m4 (gl_PREREQ_GETUSERSHELL): Likewise.
* m4/memcasecmp.m4 (gl_MEMCASECMP): Likewise.
* m4/strtod.m4 (gl_FUNC_STRTOD): Likewise.
* m4/strtol.m4 (gl_PREREQ_STRTOL): Likewise.
* m4/xstrtol.m4 (gl_PREREQ_XSTRTOL): Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 05 Jul 2006 23:35:19 +0000 (2006-07-05) |
parents | fd0ccce602e4 |
children | 8a1a9361108c |
rev | line source |
---|---|
9 | 1 /* getusershell.c -- Return names of valid user shells. |
5318
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4827
diff
changeset
|
2 |
6927
fa896bb33133
* lib/memcasecmp.c: Include <limits.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
3 Copyright (C) 1991, 1997, 2000, 2001, 2003, 2004, 2005, 2006 Free |
fa896bb33133
* lib/memcasecmp.c: Include <limits.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
4 Software Foundation, Inc. |
9 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
651
242f0fe39aa7
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
307
diff
changeset
|
17 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5813
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
9 | 19 |
20 /* Written by David MacKenzie <djm@gnu.ai.mit.edu> */ | |
21 | |
125 | 22 #ifdef HAVE_CONFIG_H |
653 | 23 # include <config.h> |
125 | 24 #endif |
25 | |
9 | 26 #ifndef SHELLS_FILE |
3052
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
27 # ifndef __DJGPP__ |
9 | 28 /* File containing a list of nonrestricted shells, one per line. */ |
3052
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
29 # define SHELLS_FILE "/etc/shells" |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
30 # else |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
31 /* This is a horrible kludge. Isn't there a better way? */ |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
32 # define SHELLS_FILE "/dev/env/DJDIR/etc/shells" |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
33 # endif |
9 | 34 #endif |
35 | |
4655 | 36 #include <stdlib.h> |
9 | 37 #include <ctype.h> |
5318
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4827
diff
changeset
|
38 |
6275 | 39 #include "stdio--.h" |
2654
c0220b12ea7d
(xmalloc, xrealloc): Remove functions.
Jim Meyering <jim@meyering.net>
parents:
1041
diff
changeset
|
40 #include "xalloc.h" |
9 | 41 |
5318
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4827
diff
changeset
|
42 #if USE_UNLOCKED_IO |
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4827
diff
changeset
|
43 # include "unlocked-io.h" |
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4827
diff
changeset
|
44 #endif |
7c24a825b51d
Remove dependencies on unlocked-io.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4827
diff
changeset
|
45 |
4656
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
46 static size_t readname (char **, size_t *, FILE *); |
9 | 47 |
3052
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
48 #if ! defined ADDITIONAL_DEFAULT_SHELLS && defined __MSDOS__ |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
49 # define ADDITIONAL_DEFAULT_SHELLS \ |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
50 "c:/dos/command.com", "c:/windows/command.com", "c:/command.com", |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
51 #else |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
52 # define ADDITIONAL_DEFAULT_SHELLS /* empty */ |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
53 #endif |
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
54 |
9 | 55 /* List of shells to use if the shells file is missing. */ |
16
01c6d40adf9d
Make tables static and const when possible.
Jim Meyering <jim@meyering.net>
parents:
9
diff
changeset
|
56 static char const* const default_shells[] = |
9 | 57 { |
3052
5d2b5bde7c6f
[!SHELLS_FILE && __DJGPP__]: Define
Jim Meyering <jim@meyering.net>
parents:
2966
diff
changeset
|
58 ADDITIONAL_DEFAULT_SHELLS |
9 | 59 "/bin/sh", "/bin/csh", "/usr/bin/sh", "/usr/bin/csh", NULL |
60 }; | |
61 | |
62 /* Index of the next shell in `default_shells' to return. | |
63 0 means we are not using `default_shells'. */ | |
4656
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
64 static size_t default_index = 0; |
9 | 65 |
66 /* Input stream from the shells file. */ | |
67 static FILE *shellstream = NULL; | |
68 | |
69 /* Line of input from the shells file. */ | |
70 static char *line = NULL; | |
71 | |
72 /* Number of bytes allocated for `line'. */ | |
4656
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
73 static size_t line_size = 0; |
9 | 74 |
75 /* Return an entry from the shells file, ignoring comment lines. | |
167 | 76 If the file doesn't exist, use the list in DEFAULT_SHELLS (above). |
77 In any case, the returned string is in memory allocated through malloc. | |
9 | 78 Return NULL if there are no more entries. */ |
79 | |
80 char * | |
4655 | 81 getusershell (void) |
9 | 82 { |
83 if (default_index > 0) | |
84 { | |
85 if (default_shells[default_index]) | |
86 /* Not at the end of the list yet. */ | |
167 | 87 return xstrdup (default_shells[default_index++]); |
9 | 88 return NULL; |
89 } | |
90 | |
91 if (shellstream == NULL) | |
92 { | |
6275 | 93 shellstream = fopen (SHELLS_FILE, "r"); |
9 | 94 if (shellstream == NULL) |
95 { | |
96 /* No shells file. Use the default list. */ | |
97 default_index = 1; | |
167 | 98 return xstrdup (default_shells[0]); |
9 | 99 } |
100 } | |
101 | |
102 while (readname (&line, &line_size, shellstream)) | |
103 { | |
104 if (*line != '#') | |
105 return line; | |
106 } | |
107 return NULL; /* End of file. */ | |
108 } | |
109 | |
110 /* Rewind the shells file. */ | |
111 | |
112 void | |
4655 | 113 setusershell (void) |
9 | 114 { |
115 default_index = 0; | |
2966
8d2c63fa3a16
(setusershell): Use rewind rather than
Jim Meyering <jim@meyering.net>
parents:
2928
diff
changeset
|
116 if (shellstream) |
8d2c63fa3a16
(setusershell): Use rewind rather than
Jim Meyering <jim@meyering.net>
parents:
2928
diff
changeset
|
117 rewind (shellstream); |
9 | 118 } |
119 | |
120 /* Close the shells file. */ | |
121 | |
122 void | |
4655 | 123 endusershell (void) |
9 | 124 { |
125 if (shellstream) | |
126 { | |
127 fclose (shellstream); | |
128 shellstream = NULL; | |
129 } | |
130 } | |
131 | |
132 /* Read a line from STREAM, removing any newline at the end. | |
133 Place the result in *NAME, which is malloc'd | |
134 and/or realloc'd as necessary and can start out NULL, | |
135 and whose size is passed and returned in *SIZE. | |
136 | |
4656
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
137 Return the number of bytes placed in *NAME |
9 | 138 if some nonempty sequence was found, otherwise 0. */ |
139 | |
4656
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
140 static size_t |
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
141 readname (char **name, size_t *size, FILE *stream) |
9 | 142 { |
143 int c; | |
4656
4f4fb4d3874d
(readname, default_index, line_size, readname):
Paul Eggert <eggert@cs.ucla.edu>
parents:
4655
diff
changeset
|
144 size_t name_index = 0; |
9 | 145 |
146 /* Skip blank space. */ | |
6927
fa896bb33133
* lib/memcasecmp.c: Include <limits.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
147 while ((c = getc (stream)) != EOF && isspace (c)) |
9 | 148 /* Do nothing. */ ; |
790 | 149 |
4827
a6d03da0fa67
Simplify the code by using new xalloc.h features.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4656
diff
changeset
|
150 for (;;) |
9 | 151 { |
4827
a6d03da0fa67
Simplify the code by using new xalloc.h features.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4656
diff
changeset
|
152 if (*size <= name_index) |
a6d03da0fa67
Simplify the code by using new xalloc.h features.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4656
diff
changeset
|
153 *name = x2nrealloc (*name, size, sizeof **name); |
6927
fa896bb33133
* lib/memcasecmp.c: Include <limits.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
154 if (c == EOF || isspace (c)) |
4827
a6d03da0fa67
Simplify the code by using new xalloc.h features.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4656
diff
changeset
|
155 break; |
9 | 156 (*name)[name_index++] = c; |
157 c = getc (stream); | |
158 } | |
159 (*name)[name_index] = '\0'; | |
160 return name_index; | |
161 } | |
162 | |
163 #ifdef TEST | |
4655 | 164 int |
165 main (void) | |
9 | 166 { |
167 char *s; | |
168 | |
169 while (s = getusershell ()) | |
170 puts (s); | |
171 exit (0); | |
172 } | |
173 #endif |