summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@redhat.com>1995-09-11 18:04:00 +0000
committerRoland McGrath <roland@redhat.com>1995-09-11 18:04:00 +0000
commit6e19c6febbbba23dcfb5215a422f45142e022ca4 (patch)
tree8c056d9ac20111af98765ffb071f3ce14abe587a
parent4314e2f98741a41c94ef05aee846b4f50d8a0477 (diff)
downloadgunmake-6e19c6febbbba23dcfb5215a422f45142e022ca4.tar.gz
Updated from libc
-rw-r--r--glob/glob.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/glob/glob.c b/glob/glob.c
index 1354150..90dd9d9 100644
--- a/glob/glob.c
+++ b/glob/glob.c
@@ -410,14 +410,23 @@ glob (pattern, flags, errfunc, pglob)
if (flags & GLOB_MARK)
{
- /* Append slashes to directory names. glob_in_dir has already
- allocated the extra character for us. */
+ /* Append slashes to directory names. */
int i;
struct stat st;
for (i = oldcount; i < pglob->gl_pathc; ++i)
if (__lstat (pglob->gl_pathv[i], &st) == 0 &&
S_ISDIR (st.st_mode))
- strcat (pglob->gl_pathv[i], "/");
+ {
+ size_t len = strlen (pglob->gl_pathv[i]) + 2;
+ char *new = realloc (pglob->gl_pathv[i], len);
+ if (new == NULL)
+ {
+ globfree (pglob);
+ return GLOB_NOSPACE;
+ }
+ strcpy (&new[len - 2], "/");
+ pglob->gl_pathv[i] = new;
+ }
}
if (!(flags & GLOB_NOSORT))
@@ -617,7 +626,7 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
if (len == 0)
len = strlen (name);
new->name
- = (char *) malloc (len + ((flags & GLOB_MARK) ? 1 : 0) + 1);
+ = (char *) malloc (len + 1);
if (new->name == NULL)
goto memory_error;
memcpy ((__ptr_t) new->name, name, len);
@@ -635,7 +644,7 @@ glob_in_dir (pattern, directory, flags, errfunc, pglob)
nfound = 1;
names = (struct globlink *) __alloca (sizeof (struct globlink));
names->next = NULL;
- names->name = (char *) malloc (len + ((flags & GLOB_MARK) ? 1 : 0) + 1);
+ names->name = (char *) malloc (len + 1);
if (names->name == NULL)
goto memory_error;
memcpy (names->name, pattern, len);