1 /* setusershell(), getusershell(), endusershell() for uClibc.
3 * Copyright (C) 2010 Bernhard Reutner-Fischer <uclibc@uclibc.org>
5 * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in
9 * The getusershell() function returns the next line from the file
10 * /etc/shells, opening the file if necessary. The line should contain
11 * the pathname of a valid user shell. If /etc/shells does not exist
12 * or is unreadable, getusershell() behaves as if /bin/sh and /bin/csh
13 * were listed in the file.
14 * The getusershell() function returns a NULL pointer on end-of-file.
20 #include "internal/parse_config.h"
22 #if defined __USE_BSD || (defined __USE_XOPEN && !defined __USE_UNIX98)
24 static const char * const defaultsh
[] = { _PATH_BSHELL
, _PATH_CSHELL
, NULL
};
25 static char *shellb
, **shells
;
26 static parser_t
*shellp
;
28 void endusershell(void)
31 shells
= (char**) shellb
;
32 while (shells
&& *shells
) {
43 libc_hidden_def(endusershell
)
45 void setusershell(void)
48 shellp
= config_open(_PATH_SHELLS
);
50 shells
= (char **)defaultsh
;
55 while (config_read(shellp
, &shell
, 1, 1, "# \t", PARSE_NORMAL
))
57 shellb
= realloc(shellb
, (pos
+ 2) * sizeof(char*));
58 shells
= (char**) shellb
+ pos
++;
59 *shells
++ = strdup(*shell
);
63 shells
= (char **)shellb
;
66 libc_hidden_def(setusershell
)
68 char *getusershell(void)