1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-29 11:41:21 +03:00

* misc/getusershell.c (okshells): Don't use static initializers,

do it dynamically.
This commit is contained in:
Ulrich Drepper
2006-05-15 18:57:25 +00:00
parent fd5ea23820
commit 02264020bf
2 changed files with 19 additions and 7 deletions

View File

@ -1,5 +1,8 @@
2006-05-15 Ulrich Drepper <drepper@redhat.com> 2006-05-15 Ulrich Drepper <drepper@redhat.com>
* misc/getusershell.c (okshells): Don't use static initializers,
do it dynamically.
* stdlib/fmtmsg.c (keywords): Change type of len element to * stdlib/fmtmsg.c (keywords): Change type of len element to
uint32_t to not waste space on 64bit machines. uint32_t to not waste space on 64bit machines.

View File

@ -46,7 +46,15 @@ static char sccsid[] = "@(#)getusershell.c 8.1 (Berkeley) 6/4/93";
* /etc/shells. * /etc/shells.
*/ */
/* NB: we do not initialize okshells here. The initialization needs
relocations. These interfaces are used so rarely that this is not
justified. Instead explicitly initialize the array when it is
used. */
#if 0
static const char *const okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL }; static const char *const okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL };
#else
static const char *okshells[3];
#endif
static char **curshell, **shells, *strings; static char **curshell, **shells, *strings;
static char **initshells (void) __THROW; static char **initshells (void) __THROW;
@ -97,21 +105,22 @@ initshells()
free(strings); free(strings);
strings = NULL; strings = NULL;
if ((fp = fopen(_PATH_SHELLS, "rc")) == NULL) if ((fp = fopen(_PATH_SHELLS, "rc")) == NULL)
return (char **) okshells; goto init_okshells_noclose;
if (fstat64(fileno(fp), &statb) == -1) { if (fstat64(fileno(fp), &statb) == -1) {
init_okshells:
(void)fclose(fp); (void)fclose(fp);
init_okshells_noclose:
okshells[0] = _PATH_BSHELL;
okshells[1] = _PATH_CSHELL;
return (char **) okshells; return (char **) okshells;
} }
if ((strings = malloc((u_int)statb.st_size + 1)) == NULL) { if ((strings = malloc((u_int)statb.st_size + 1)) == NULL)
(void)fclose(fp); goto init_okshells;
return (char **) okshells;
}
shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); shells = calloc((unsigned)statb.st_size / 3, sizeof (char *));
if (shells == NULL) { if (shells == NULL) {
(void)fclose(fp);
free(strings); free(strings);
strings = NULL; strings = NULL;
return (char **) okshells; goto init_okshells;
} }
sp = shells; sp = shells;
cp = strings; cp = strings;