From: Jim Meyering Date: Wed, 5 Feb 2003 16:35:07 +0000 (+0000) Subject: Include . X-Git-Tag: v4.5.6~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03975e728debdbe5ad3eb08ab1bfd7573224a174;p=thirdparty%2Fcoreutils.git Include . (PATH_MAX): Define to 1024, if not already defined. (process_entry): Allocate enough space to hold the resulting file name. Don't presume that 2*dirbufsize is enough. (ftw_startup): Always use PATH_MAX to compute buffer size, now that it is guaranteed to be defined. --- diff --git a/lib/ftw.c b/lib/ftw.c index 3928cdaf9d..ceed7fdea1 100644 --- a/lib/ftw.c +++ b/lib/ftw.c @@ -73,6 +73,11 @@ char *alloca (); # include #endif +#include +#ifndef PATH_MAX +# define PATH_MAX 1024 +#endif + #if ! _LIBC && !HAVE_DECL_STPCPY && !defined stpcpy char *stpcpy (); #endif @@ -349,18 +354,20 @@ process_entry (struct ftw_data *data, struct dir_data *dir, const char *name, struct STAT st; int result = 0; int flag = 0; + size_t new_buflen; if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) /* Don't process the "." and ".." entries. */ return 0; - if (data->dirbufsize < data->ftw.base + namlen + 2) + new_buflen = data->ftw.base + namlen + 2; + if (data->dirbufsize < new_buflen) { /* Enlarge the buffer. */ char *newp; - data->dirbufsize *= 2; + data->dirbufsize = 2 * new_buflen; newp = (char *) realloc (data->dirbuf, data->dirbufsize); if (newp == NULL) return -1; @@ -650,11 +657,7 @@ ftw_startup (const char *dir, int is_nftw, void *func, int descriptors, memset (data.dirstreams, '\0', data.maxdir * sizeof (struct dir_data *)); dir_len = strlen (dir); -#ifdef PATH_MAX data.dirbufsize = MAX (2 * dir_len, PATH_MAX); -#else - data.dirbufsize = 2 * dir_len; -#endif data.dirbuf = (char *) malloc (data.dirbufsize); if (data.dirbuf == NULL) return -1;