X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fsavedir.c;h=538f397cb6456aace6dc02cc4c70bc8b15a6338f;hb=11b16d3cdc4646f80822751dc6882b21c9da2a22;hp=8400145ad884c98247452f727a7726d1276165d0;hpb=d1aa3e40286ed2b0ad1045b326a37167ac5d8847;p=gnulib.git diff --git a/lib/savedir.c b/lib/savedir.c index 8400145ad..538f397cb 100644 --- a/lib/savedir.c +++ b/lib/savedir.c @@ -1,7 +1,7 @@ /* savedir.c -- save the list of files in a directory in a string - Copyright (C) 1990, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, - 2006, 2009 Free Software Foundation, Inc. + Copyright (C) 1990, 1997-2001, 2003-2006, 2009-2010 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 @@ -26,9 +26,9 @@ #include -#include +#include "dirent--.h" #ifndef _D_EXACT_NAMLEN -# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name) +# define _D_EXACT_NAMLEN(dp) strlen ((dp)->d_name) #endif #include @@ -41,11 +41,6 @@ # define NAME_SIZE_DEFAULT 512 #endif -/* The results of opendir() in this file are not used with dirfd and fchdir, - therefore save some unnecessary work in fchdir.c. */ -#undef opendir -#undef closedir - /* Return a freshly allocated string containing the file names in directory DIRP, separated by '\0' characters; the end is marked by two '\0' characters in a row. @@ -73,31 +68,31 @@ savedirstream (DIR *dirp) errno = 0; dp = readdir (dirp); if (! dp) - break; + break; /* Skip "", ".", and "..". "" is returned by at least one buggy implementation: Solaris 2.4 readdir on NFS file systems. */ entry = dp->d_name; if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0') - { - size_t entry_size = _D_EXACT_NAMLEN (dp) + 1; - if (used + entry_size < used) - xalloc_die (); - if (allocated <= used + entry_size) - { - do - { - if (2 * allocated < allocated) - xalloc_die (); - allocated *= 2; - } - while (allocated <= used + entry_size); - - name_space = xrealloc (name_space, allocated); - } - memcpy (name_space + used, entry, entry_size); - used += entry_size; - } + { + size_t entry_size = _D_EXACT_NAMLEN (dp) + 1; + if (used + entry_size < used) + xalloc_die (); + if (allocated <= used + entry_size) + { + do + { + if (2 * allocated < allocated) + xalloc_die (); + allocated *= 2; + } + while (allocated <= used + entry_size); + + name_space = xrealloc (name_space, allocated); + } + memcpy (name_space + used, entry, entry_size); + used += entry_size; + } } name_space[used] = '\0'; save_errno = errno;