diff options
author | Jim Meyering <jim@meyering.net> | 2004-04-04 06:51:11 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2004-04-04 06:51:11 +0000 |
commit | 8c5584a1513cdbf62e8ed51c69053db4aae44682 (patch) | |
tree | 33f6842b5ab8d3e40869af4574990cfe15c3e50e /lib/getusershell.c | |
parent | fef16409575921ce744f360ed21800a6207d9f8f (diff) | |
download | coreutils-8c5584a1513cdbf62e8ed51c69053db4aae44682.tar.xz |
Sync from gnulib.
Diffstat (limited to 'lib/getusershell.c')
-rw-r--r-- | lib/getusershell.c | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/lib/getusershell.c b/lib/getusershell.c index c026ec0a9..9b60f18d5 100644 --- a/lib/getusershell.c +++ b/lib/getusershell.c @@ -145,29 +145,17 @@ readname (char **name, size_t *size, FILE *stream) int c; size_t name_index = 0; - if (*name == NULL) - { - /* The initial size must be a power of two, so that the overflow - check works. */ - *size = 16; - - *name = xmalloc (*size); - } - /* Skip blank space. */ while ((c = getc (stream)) != EOF && ISSPACE (c)) /* Do nothing. */ ; - while (c != EOF && !ISSPACE (c)) + for (;;) { + if (*size <= name_index) + *name = x2nrealloc (*name, size, sizeof **name); + if (c == EOF || ISSPACE (c)) + break; (*name)[name_index++] = c; - if (*size < name_index) - { - *size *= 2; - if (! *size) - xalloc_die (); - *name = xrealloc (*name, *size); - } c = getc (stream); } (*name)[name_index] = '\0'; |