Remove unused scandir() compat implementation
scandir() isn't used anywhere within the client, so we don't need to bother with a compat implementation for systems that don't have it.
This commit is contained in:
120
source/compat.c
120
source/compat.c
@@ -876,126 +876,6 @@ unsigned long strtoul (const char *nptr, char **endptr, int base)
|
||||
#endif /* DO NOT HAVE STRTOUL */
|
||||
/* --- end of strtoul.c --- */
|
||||
|
||||
/* --- start of scandir.c --- */
|
||||
#ifndef HAVE_SCANDIR
|
||||
/*
|
||||
* Scandir.c -- A painful file for painful operating systems
|
||||
*
|
||||
* Technically, scandir is not a "standard" function. It belongs to
|
||||
* 4.2BSD derived systems, and most everone that has any repsect for their
|
||||
* customers implements it sanely. Which probably explains why its broken
|
||||
* on Solaris 2.
|
||||
*
|
||||
* I removed the 4BSD scandir function because it required intimite knowledge
|
||||
* of what was inside the DIR type, which sort of defeats the point. What I
|
||||
* left was this extremely generic scandir function that only depends on
|
||||
* opendir(), readdir(), and closedir(), and perhaps the DIRSIZ macro.
|
||||
* The only member of struct dirent we peer into is d_name.
|
||||
*
|
||||
* Public domain
|
||||
*/
|
||||
|
||||
|
||||
#define RESIZEDIR(x, y, z) x = realloc((void *)(x), sizeof(y) * (z))
|
||||
|
||||
/* Initial guess at directory size. */
|
||||
#define INITIAL_SIZE 30
|
||||
|
||||
typedef struct dirent DIRENT;
|
||||
|
||||
/*
|
||||
* If the system doesnt have a way to tell us how big a directory entry
|
||||
* is, then we make a wild guess. This shouldnt ever be SMALLER than
|
||||
* the actual size, and if its larger, so what? This will probably not
|
||||
* be a size thats divisible by 4, so the memcpy() may not be super
|
||||
* efficient. But so what? Any system that cant provide a decent scandir
|
||||
* im not worried about efficiency.
|
||||
*/
|
||||
/* The SCO hack is at the advice of FireClown, thanks! =) */
|
||||
#if defined(_SCO_DS)
|
||||
# undef DIRSIZ
|
||||
#endif
|
||||
|
||||
#ifndef DIRSIZ
|
||||
# define DIRSIZ(d) (sizeof(DIRENT) + strlen(d->d_name) + 1)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Scan the directory dirname calling select to make a list of selected
|
||||
* directory entries then sort using qsort and compare routine dcomp. Returns
|
||||
* the number of entries and a pointer to a list of pointers to struct direct
|
||||
* (through namelist). Returns -1 if there were any errors.
|
||||
*/
|
||||
int scandir (const char *name,
|
||||
DIRENT ***list,
|
||||
int (*selector) (DIRENT *),
|
||||
int (*sorter) (const void *, const void *))
|
||||
{
|
||||
DIRENT **names;
|
||||
static DIRENT *e;
|
||||
DIR *dp;
|
||||
int i;
|
||||
int size = INITIAL_SIZE;
|
||||
|
||||
if (!(names = (DIRENT **)malloc(size * sizeof(DIRENT *))))
|
||||
return -1;
|
||||
|
||||
if (access(name, R_OK | X_OK))
|
||||
return -1;
|
||||
|
||||
if (!(dp = opendir(name)))
|
||||
return -1;
|
||||
|
||||
/* Read entries in the directory. */
|
||||
for (i = 0; (e = readdir(dp));)
|
||||
{
|
||||
if (!selector || (*selector)(e))
|
||||
{
|
||||
if (i + 1 >= size)
|
||||
{
|
||||
size <<= 1;
|
||||
RESIZEDIR(names, DIRENT *, size);
|
||||
if (!names)
|
||||
{
|
||||
closedir(dp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
names[i] = (DIRENT *)malloc(DIRSIZ(e));
|
||||
if (names[i] == NULL)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < i; j++)
|
||||
free(names[j]);
|
||||
free(names);
|
||||
closedir(dp);
|
||||
return -1;
|
||||
}
|
||||
memcpy(names[i], e, DIRSIZ(e));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Truncate the "names" array down to its actual size (why?)
|
||||
*/
|
||||
RESIZEDIR(names, DIRENT *, i + 2);
|
||||
names[i + 1] = 0;
|
||||
*list = names;
|
||||
closedir(dp);
|
||||
|
||||
/*
|
||||
* Sort if neccesary...
|
||||
*/
|
||||
if (i && sorter)
|
||||
qsort(names, i, sizeof(DIRENT *), sorter);
|
||||
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
/* --- end of scandir.c --- */
|
||||
|
||||
/* --- start of env.c --- */
|
||||
#ifndef HAVE_SETENV
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user