Remove no-longer-used files savedir.[ch].

* lib/savedirinfo.c: delete unused file.
* lib/savedirinfo.h: delete unused file.
* lib/Makefile.am (libfind_a_SOURCES): Remove savedirinfo.c.
(EXTRA_DIST): Remove savedirinfo.h.
This commit is contained in:
James Youngman 2011-08-20 23:52:08 +01:00
parent a29e61b873
commit 81e33db099
4 changed files with 9 additions and 338 deletions

View File

@ -1,8 +1,14 @@
2011-08-20 James Youngman <jay@gnu.org>
Remove no-longer-used files savedir.[ch].
* lib/savedirinfo.c: delete unused file.
* lib/savedirinfo.h: delete unused file.
* lib/Makefile.am (libfind_a_SOURCES): Remove savedirinfo.c.
(EXTRA_DIST): Remove savedirinfo.h.
Reduce memory consumption of oldfind on large directories.
* find/find.c (process_dir): Reduce memory consumption for large
directories. Don't save the whoel directory content with
directories. Don't save the whole directory content with
xsavedir, instead just loop over the results of readdir. This
means that oldfind will consume one file descriptor per directory
level.

View File

@ -19,7 +19,7 @@ TESTS += check-regexprops test_splitstring
endif
libfind_a_SOURCES = findutils-version.c
EXTRA_DIST = extendbuf.h savedirinfo.h buildcmd.h \
EXTRA_DIST = extendbuf.h buildcmd.h \
findutils-version.h \
fdleak.h unused-result.h check-regexprops.sh
SUFFIXES =
@ -33,7 +33,7 @@ LDADD = ../gl/lib/libgnulib.a $(LIBINTL)
libfind_a_SOURCES += printquoted.h listfile.h \
regextype.h dircallback.h safe-atoi.h splitstring.h
libfind_a_SOURCES += listfile.c extendbuf.c buildcmd.c savedirinfo.c \
libfind_a_SOURCES += listfile.c extendbuf.c buildcmd.c \
forcefindlib.c qmark.c printquoted.c regextype.c dircallback.c fdleak.c \
safe-atoi.c splitstring.c

View File

@ -1,262 +0,0 @@
/* savedirinfo.c -- Save the list of files in a directory, with additional information.
Copyright 1990, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2010,
2011 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Written by James Youngman, <jay@gnu.org>. */
/* Derived from savedir.c, written by David MacKenzie <djm@gnu.org>. */
/* config.h must be included first. */
#include <config.h>
/* system headers. */
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
/* gnulib headers. */
#include "dirent-safer.h"
#include "xalloc.h"
/* find headers. */
#include "extendbuf.h"
#include "savedirinfo.h"
#ifdef CLOSEDIR_VOID
/* Fake a return value. */
# define CLOSEDIR(d) (closedir (d), 0)
#else
# define CLOSEDIR(d) closedir (d)
#endif
#if defined HAVE_STRUCT_DIRENT_D_TYPE
/* Convert the value of struct dirent.d_type into a value for
* struct stat.st_mode (at least the file type bits), or zero
* if the type is DT_UNKNOWN or is a value we don't know about.
*/
static mode_t
type_to_mode (unsigned type)
{
switch (type)
{
#ifdef DT_FIFO
case DT_FIFO: return S_IFIFO;
#endif
#ifdef DT_CHR
case DT_CHR: return S_IFCHR;
#endif
#ifdef DT_DIR
case DT_DIR: return S_IFDIR;
#endif
#ifdef DT_BLK
case DT_BLK: return S_IFBLK;
#endif
#ifdef DT_REG
case DT_REG: return S_IFREG;
#endif
#ifdef DT_LNK
case DT_LNK: return S_IFLNK;
#endif
#ifdef DT_SOCK
case DT_SOCK: return S_IFSOCK;
#endif
default:
return 0; /* Unknown. */
}
}
#endif
struct new_savedir_direntry_internal
{
int flags; /* from SaveDirDataFlags */
mode_t type_info;
size_t buffer_offset;
};
static int
savedir_cmp (const void *p1, const void *p2)
{
const struct savedir_direntry *de1, *de2;
de1 = p1;
de2 = p2;
return strcmp (de1->name, de2->name); /* POSIX order, not locale order. */
}
static struct savedir_direntry*
convertentries (const struct savedir_dirinfo *info,
struct new_savedir_direntry_internal *internal)
{
char *p = info->buffer;
struct savedir_direntry *result;
int n =info->size;
int i;
result = xmalloc (sizeof (*result) * info->size);
for (i=0; i<n; ++i)
{
result[i].flags = internal[i].flags;
result[i].type_info = internal[i].type_info;
result[i].name = &p[internal[i].buffer_offset];
}
return result;
}
struct savedir_dirinfo *
xsavedir (const char *dir, int flags)
{
DIR *dirp;
struct dirent *dp;
struct savedir_dirinfo *result = NULL;
struct new_savedir_direntry_internal *internal;
size_t namebuf_allocated = 0u, namebuf_used = 0u;
size_t entrybuf_allocated = 0u;
int save_errno;
dirp = opendir_safer (dir);
if (dirp == NULL)
return NULL;
errno = 0;
result = xmalloc (sizeof (*result));
result->buffer = NULL;
result->size = 0u;
result->entries = NULL;
internal = NULL;
while ((dp = readdir (dirp)) != NULL)
{
/* Skip "", ".", and "..". "" is returned by at least one buggy
implementation: Solaris 2.4 readdir on NFS file systems. */
char const *entry = dp->d_name;
if (entry[entry[0] != '.' ? 0 : entry[1] != '.' ? 1 : 2] != '\0')
{
/* Remember the name. */
size_t entry_size = strlen (entry) + 1;
result->buffer = xextendbuf (result->buffer, namebuf_used+entry_size, &namebuf_allocated);
memcpy ((result->buffer) + namebuf_used, entry, entry_size);
/* Remember the other stuff. */
internal = xextendbuf (internal, (1+result->size)*sizeof (*internal), &entrybuf_allocated);
internal[result->size].flags = 0;
internal[result->size].type_info = 0;
#if defined HAVE_STRUCT_DIRENT_D_TYPE
internal[result->size].type_info = type_to_mode (dp->d_type);
if (dp->d_type != DT_UNKNOWN)
internal[result->size].flags |= SavedirHaveFileType;
#endif
internal[result->size].buffer_offset = namebuf_used;
/* Prepare for the next iteration */
++(result->size);
namebuf_used += entry_size;
}
}
result->buffer = xextendbuf (result->buffer, namebuf_used+1, &namebuf_allocated);
result->buffer[namebuf_used] = '\0';
/* convert the result to its externally-usable form. */
result->entries = convertentries (result, internal);
free (internal);
internal = NULL;
if (flags & SavedirSort)
{
qsort (result->entries,
result->size, sizeof (*result->entries),
savedir_cmp);
}
save_errno = errno;
if (CLOSEDIR (dirp) != 0)
save_errno = errno;
if (save_errno != 0)
{
free (result->buffer);
free (result);
errno = save_errno;
return NULL;
}
return result;
}
void free_dirinfo (struct savedir_dirinfo *p)
{
free (p->entries);
p->entries = NULL;
free (p->buffer);
p->buffer = NULL;
free (p);
}
char *
savedirinfo (const char *dir, struct savedir_extrainfo **extra)
{
struct savedir_dirinfo *p = xsavedir (dir, SavedirSort);
char *buf, *s;
size_t bufbytes = 0;
unsigned int i;
if (p)
{
struct savedir_extrainfo *pex = xmalloc (p->size * sizeof (*extra));
for (i=0; i<p->size; ++i)
{
bufbytes += strlen (p->entries[i].name);
++bufbytes; /* the \0 */
pex[i].type_info = p->entries[i].type_info;
}
s = buf = xmalloc (bufbytes+1);
for (i=0; i<p->size; ++i)
{
size_t len = strlen (p->entries[i].name);
memcpy (s, p->entries[i].name, len);
s += len;
*s = 0; /* Place a NUL */
++s; /* Skip the NUL. */
}
*s = 0; /* final (doubled) terminating NUL */
if (extra)
*extra = pex;
else
free (pex);
return buf;
}
else
{
return NULL;
}
}

View File

@ -1,73 +0,0 @@
/* Save the list of files in a directory, with additional information.
Copyright 1997, 1999, 2001, 2003, 2005, 2010, 2011 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* Written by James Youngman <jay@gnu.org>.
* Based on savedir.h by David MacKenzie <djm@gnu.org>.
*/
#if !defined SAVEDIRINFO_H_
# define SAVEDIRINFO_H_
typedef enum tagSaveDirControlFlags
{
SavedirSort = 1
}
SaveDirControlFlags;
typedef enum tagSaveDirDataFlags
{
SavedirHaveFileType = 1
}
SaveDirDataFlags;
/* We keep the name and the type in a structure together
* to allow us to sort them together.
*/
struct savedir_direntry
{
int flags; /* from SaveDirDataFlags */
char *name; /* the name of the directory entry */
mode_t type_info; /* the type (or zero if unknown) */
};
struct savedir_dirinfo
{
char *buffer; /* The names are stored here. */
size_t size; /* The total number of results. */
struct savedir_direntry *entries; /* The results themselves */
};
struct savedir_extrainfo
{
mode_t type_info;
};
/* savedirinfo() is the old interface. */
char *savedirinfo (const char *dir, struct savedir_extrainfo **extra);
/* savedir() is the 'new' interface, but the function has the same name
* as the function from findutils 4.1.7 and 4.1.20.
*/
struct savedir_dirinfo * xsavedir(const char *dir, int flags);
void free_dirinfo(struct savedir_dirinfo *p);
#endif