(savedir): Don't assume that xrealloc etc. leave errno alone.

This commit is contained in:
Paul Eggert 2005-10-28 23:06:42 +00:00
parent cada888edd
commit 5648577df0
2 changed files with 15 additions and 4 deletions

View File

@ -1,3 +1,8 @@
2005-10-28 Paul Eggert <eggert@cs.ucla.edu>
* savedir.c (savedir): Don't assume that xrealloc etc. leave
errno alone. Problem reported by Frederic Jolliton.
2005-10-24 Jim Meyering <jim@meyering.net>
* mkdir-p.c (make_dir_parents): Like the code above, don't rely

View File

@ -70,7 +70,6 @@ char *
savedir (const char *dir)
{
DIR *dirp;
struct dirent *dp;
char *name_space;
size_t allocated = NAME_SIZE_DEFAULT;
size_t used = 0;
@ -82,12 +81,19 @@ savedir (const char *dir)
name_space = xmalloc (allocated);
errno = 0;
while ((dp = readdir (dirp)) != NULL)
for (;;)
{
struct dirent const *dp;
char const *entry;
errno = 0;
dp = readdir (dirp);
if (! dp)
break;
/* Skip "", ".", and "..". "" is returned by at least one buggy
implementation: Solaris 2.4 readdir on NFS file systems. */
char const *entry = dp->d_name;
entry = dp->d_name;
if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
{
size_t entry_size = strlen (entry) + 1;