diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-10-28 23:06:42 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-10-28 23:06:42 +0000 |
commit | 5648577df01d1f210790aaeec645c767137316eb (patch) | |
tree | 23efa535111cbe1eaff99045bf313b37bce0ceff | |
parent | cada888edd97257080dd431494e20bbd313bad1a (diff) | |
download | coreutils-5648577df01d1f210790aaeec645c767137316eb.tar.xz |
(savedir): Don't assume that xrealloc etc. leave errno alone.
-rw-r--r-- | lib/ChangeLog | 5 | ||||
-rw-r--r-- | lib/savedir.c | 14 |
2 files changed, 15 insertions, 4 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index 87e3d88ad..1dd26ac7a 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -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 diff --git a/lib/savedir.c b/lib/savedir.c index a2cf2f678..86930eb56 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -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; |