glob: repair for systems without d_type field in struct dirent
The d_type field in struct dirent is not mandated by POSIX and is missing e.g. on MinGW where this leads to a failing build. Fall back to using stat() here.
This commit is contained in:
parent
bfb2dd3faa
commit
67d4033dab
1 changed files with 34 additions and 1 deletions
35
src/i_glob.c
35
src/i_glob.c
|
|
@ -36,6 +36,39 @@
|
|||
|
||||
#ifndef NO_DIRENT_IMPLEMENTATION
|
||||
|
||||
// Only the fields d_name and (as an XSI extension) d_ino are specified
|
||||
// in POSIX.1. Other than Linux, the d_type field is available mainly
|
||||
// only on BSD systems. The remaining fields are available on many, but
|
||||
// not all systems.
|
||||
#if defined(_DIRENT_HAVE_D_TYPE)
|
||||
static boolean IsDirectory(char *dir, struct dirent *de)
|
||||
{
|
||||
return de->d_type == DT_DIR;
|
||||
}
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static boolean IsDirectory(char *dir, struct dirent *de)
|
||||
{
|
||||
char *filename;
|
||||
struct stat sb;
|
||||
int result;
|
||||
|
||||
filename = M_StringJoin(dir, DIR_SEPARATOR_S, de->d_name, NULL);
|
||||
result = stat(filename, &sb);
|
||||
free(filename);
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISDIR(sb.st_mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct glob_s
|
||||
{
|
||||
char *glob;
|
||||
|
|
@ -126,7 +159,7 @@ const char *I_NextGlob(glob_t *glob)
|
|||
{
|
||||
return NULL;
|
||||
}
|
||||
} while (de->d_type == DT_DIR || !MatchesGlob(de->d_name, glob->glob));
|
||||
} while (IsDirectory(glob->directory, de) || !MatchesGlob(de->d_name, glob->glob));
|
||||
|
||||
// Return the fully-qualified path, not just the bare filename.
|
||||
free(glob->last_filename);
|
||||
|
|
|
|||
Loading…
Reference in a new issue