mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
Remove unused scandir() check and fallback implementation.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@23799 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
b6b143c5dc
commit
b21bbf2505
20
configure
vendored
20
configure
vendored
@ -3323,22 +3323,6 @@ fi
|
||||
echores "$_shm"
|
||||
|
||||
|
||||
echocheck "scandir()"
|
||||
cat > $TMPC << EOF
|
||||
int main (void) { scandir("", 0, 0, 0); alphasort(0, 0); return 0; }
|
||||
EOF
|
||||
_scandir=no
|
||||
cc_check && _scandir=yes
|
||||
if test "$_scandir" = yes ; then
|
||||
_def_scandir='#define HAVE_SCANDIR 1'
|
||||
_need_scandir=no
|
||||
else
|
||||
_def_scandir='#undef HAVE_SCANDIR'
|
||||
_need_scandir=yes
|
||||
fi
|
||||
echores "$_scandir"
|
||||
|
||||
|
||||
echocheck "strsep()"
|
||||
cat > $TMPC << EOF
|
||||
#include <string.h>
|
||||
@ -7396,7 +7380,6 @@ HAVE_POSIX_SELECT = $_posix_select
|
||||
|
||||
NEED_GETTIMEOFDAY = $_need_gettimeofday
|
||||
NEED_GLOB = $_need_glob
|
||||
NEED_SCANDIR = $_need_scandir
|
||||
NEED_SETENV = $_need_setenv
|
||||
NEED_SHMEM = $_need_shmem
|
||||
NEED_STRSEP = $_need_strsep
|
||||
@ -7749,9 +7732,6 @@ $_def_zlib
|
||||
/* Define this if you have shm support */
|
||||
$_def_shm
|
||||
|
||||
/* Define this if your system has scandir & alphasort */
|
||||
$_def_scandir
|
||||
|
||||
/* Define this if your system has strsep */
|
||||
$_def_strsep
|
||||
|
||||
|
@ -7,7 +7,6 @@ SRCS_COMMON-$(MACOSX_FINDER_SUPPORT) += macosx_finder_args.c
|
||||
|
||||
SRCS_COMMON-$(NEED_GETTIMEOFDAY) += gettimeofday.c
|
||||
SRCS_COMMON-$(NEED_GLOB) += glob-win.c
|
||||
SRCS_COMMON-$(NEED_SCANDIR) += scandir.c
|
||||
SRCS_COMMON-$(NEED_SETENV) += setenv.c
|
||||
SRCS_COMMON-$(NEED_SHMEM) += shmem.c
|
||||
SRCS_COMMON-$(NEED_STRSEP) += strsep.c
|
||||
|
133
osdep/scandir.c
133
osdep/scandir.c
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* scandir, alphasort - scan a directory
|
||||
*
|
||||
* implementation for systems that do not have it in libc
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* convenience helper function for scandir's |compar()| function:
|
||||
* sort directory entries using strcoll(3)
|
||||
*/
|
||||
int
|
||||
alphasort(const void *_a, const void *_b)
|
||||
{
|
||||
struct dirent **a = (struct dirent **)_a;
|
||||
struct dirent **b = (struct dirent **)_b;
|
||||
return strcoll((*a)->d_name, (*b)->d_name);
|
||||
}
|
||||
|
||||
|
||||
#define strverscmp(a,b) strcoll(a,b) /* for now */
|
||||
|
||||
/*
|
||||
* convenience helper function for scandir's |compar()| function:
|
||||
* sort directory entries using GNU |strverscmp()|
|
||||
*/
|
||||
int
|
||||
versionsort(const void *_a, const void *_b)
|
||||
{
|
||||
struct dirent **a = (struct dirent **)_a;
|
||||
struct dirent **b = (struct dirent **)_b;
|
||||
return strverscmp((*a)->d_name, (*b)->d_name);
|
||||
}
|
||||
|
||||
/*
|
||||
* The scandir() function reads the directory dirname and builds an
|
||||
* array of pointers to directory entries using malloc(3). It returns
|
||||
* the number of entries in the array. A pointer to the array of
|
||||
* directory entries is stored in the location referenced by namelist.
|
||||
*
|
||||
* The select parameter is a pointer to a user supplied subroutine
|
||||
* which is called by scandir() to select which entries are to be
|
||||
* included in the array. The select routine is passed a pointer to
|
||||
* a directory entry and should return a non-zero value if the
|
||||
* directory entry is to be included in the array. If select is null,
|
||||
* then all the directory entries will be included.
|
||||
*
|
||||
* The compar parameter is a pointer to a user supplied subroutine
|
||||
* which is passed to qsort(3) to sort the completed array. If this
|
||||
* pointer is null, the array is not sorted.
|
||||
*/
|
||||
int
|
||||
scandir(const char *dirname,
|
||||
struct dirent ***ret_namelist,
|
||||
int (*select)(const struct dirent *),
|
||||
int (*compar)(const struct dirent **, const struct dirent **))
|
||||
{
|
||||
int i, len;
|
||||
int used, allocated;
|
||||
DIR *dir;
|
||||
struct dirent *ent, *ent2;
|
||||
struct dirent **namelist = NULL;
|
||||
|
||||
if ((dir = opendir(dirname)) == NULL)
|
||||
return -1;
|
||||
|
||||
used = 0;
|
||||
allocated = 2;
|
||||
namelist = malloc(allocated * sizeof(struct dirent *));
|
||||
if (!namelist)
|
||||
goto error;
|
||||
|
||||
while ((ent = readdir(dir)) != NULL) {
|
||||
|
||||
if (select != NULL && !select(ent))
|
||||
continue;
|
||||
|
||||
/* duplicate struct direct for this entry */
|
||||
len = offsetof(struct dirent, d_name) + strlen(ent->d_name) + 1;
|
||||
if ((ent2 = malloc(len)) == NULL)
|
||||
goto error;
|
||||
|
||||
if (used >= allocated) {
|
||||
allocated *= 2;
|
||||
namelist = realloc(namelist, allocated * sizeof(struct dirent *));
|
||||
if (!namelist)
|
||||
goto error;
|
||||
}
|
||||
memcpy(ent2, ent, len);
|
||||
namelist[used++] = ent2;
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
if (compar)
|
||||
qsort(namelist, used, sizeof(struct dirent *),
|
||||
(int (*)(const void *, const void *)) compar);
|
||||
|
||||
*ret_namelist = namelist;
|
||||
return used;
|
||||
|
||||
|
||||
error:
|
||||
closedir(dir);
|
||||
|
||||
if (namelist) {
|
||||
for (i = 0; i < used; i++)
|
||||
free(namelist[i]);
|
||||
free(namelist);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
#if STANDALONE_MAIN
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
int i, n;
|
||||
|
||||
n = scandir("/etc", &namelist, NULL, alphasort);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
printf("%s\n", namelist[i]->d_name);
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user