diff options
author | Jim Meyering <jim@meyering.net> | 2001-08-31 09:09:53 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2001-08-31 09:09:53 +0000 |
commit | 2c63fed0e8d7321196a80c581785f370df9972f5 (patch) | |
tree | 5c2d5467fc4b630a76492e0c91cd9e600a75331b /lib | |
parent | fab23e172d2bf8e1870a519f21e2b923b82abad6 (diff) | |
download | coreutils-2c63fed0e8d7321196a80c581785f370df9972f5.tar.xz |
(savedir): Remove size parameter, as POSIX says that
a directory's st_size can have an arbitrary value, so the old
usage could waste an arbitrary amount of memory. All uses
changed.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/savedir.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/lib/savedir.c b/lib/savedir.c index 5b7a6dd7f..112f5c045 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -1,5 +1,7 @@ /* savedir.c -- save the list of files in a directory in a string - Copyright (C) 1990, 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + + Copyright 1990, 1997, 1998, 1999, 2000, 2001 Free Software + Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -64,9 +66,6 @@ extern int errno; /* Return a freshly allocated string containing the filenames in directory DIR, separated by '\0' characters; the end is marked by two '\0' characters in a row. - NAME_SIZE is the number of bytes to initially allocate - for the string; it will be enlarged as needed. - Use NAME_SIZE == -1 if you do not know the size. Return NULL (setting errno) if DIR cannot be opened, read, or closed. */ #ifndef NAME_SIZE_DEFAULT @@ -74,12 +73,12 @@ extern int errno; #endif char * -savedir (const char *dir, off_t name_size) +savedir (const char *dir) { DIR *dirp; struct dirent *dp; char *name_space; - size_t allocated = name_size; /* Overflow is checked indirectly below. */ + size_t allocated = NAME_SIZE_DEFAULT; size_t used = 0; int save_errno; @@ -87,13 +86,6 @@ savedir (const char *dir, off_t name_size) if (dirp == NULL) return NULL; - /* Use the default if the size is not known. Be sure "allocated" - is at least `1' so there's room for the final NUL byte. - Do not simply test name_size <= 0, because the initialization - of "allocated" might have overflowed. */ - if (name_size < 0 || allocated == 0) - allocated = NAME_SIZE_DEFAULT; - name_space = xmalloc (allocated); errno = 0; |