FIO: Fix non Win32 behaviors of sim_dir_scan

Allow for a file not found case to be determined and explicit file and
full directory scan when GLOB and FNMATCH aren't available.
This commit is contained in:
Mark Pizzolato 2019-12-30 13:12:41 -08:00
parent 236716845a
commit d131f66c40

View file

@ -953,6 +953,7 @@ glob_t paths;
#else #else
DIR *dir; DIR *dir;
#endif #endif
int found_count = 0;
struct stat filestat; struct stat filestat;
char *c; char *c;
char DirName[PATH_MAX + 1], WholeName[PATH_MAX + 1], WildName[PATH_MAX + 1]; char DirName[PATH_MAX + 1], WholeName[PATH_MAX + 1], WildName[PATH_MAX + 1];
@ -982,7 +983,7 @@ if (dir) {
struct dirent *ent; struct dirent *ent;
#endif #endif
t_offset FileSize; t_offset FileSize;
char FileName[PATH_MAX + 1]; char *FileName;
const char *MatchName = 1 + strrchr (cptr, '/'); const char *MatchName = 1 + strrchr (cptr, '/');
char *p_name; char *p_name;
struct tm *local; struct tm *local;
@ -992,24 +993,29 @@ if (dir) {
#if defined (HAVE_GLOB) #if defined (HAVE_GLOB)
for (i=0; i<paths.gl_pathc; i++) { for (i=0; i<paths.gl_pathc; i++) {
FileName = (char *)malloc (1 + strlen (paths.gl_pathv[i]));
sprintf (FileName, "%s", paths.gl_pathv[i]); sprintf (FileName, "%s", paths.gl_pathv[i]);
#else #else /* !defined (HAVE_GLOB) */
while ((ent = readdir (dir))) { while ((ent = readdir (dir))) {
#if defined (HAVE_FNMATCH) #if defined (HAVE_FNMATCH)
if (fnmatch(MatchName, ent->d_name, 0)) if (fnmatch(MatchName, ent->d_name, 0))
continue; continue;
#else #else /* !defined (HAVE_FNMATCH) */
/* only match exact name without fnmatch support */ /* only match all names or exact name without fnmatch support */
if (strcmp(MatchName, ent->d_name) != 0) if ((strcmp(MatchName, "*") != 0) &&
(strcmp(MatchName, ent->d_name) != 0))
continue; continue;
#endif #endif /* defined (HAVE_FNMATCH) */
FileName = (char *)malloc (1 + strlen (DirName) + strlen (ent->d_name));
sprintf (FileName, "%s%s", DirName, ent->d_name); sprintf (FileName, "%s%s", DirName, ent->d_name);
#endif #endif /* defined (HAVE_GLOB) */
p_name = FileName + strlen (DirName); p_name = FileName + strlen (DirName);
memset (&filestat, 0, sizeof (filestat)); memset (&filestat, 0, sizeof (filestat));
(void)stat (FileName, &filestat); (void)stat (FileName, &filestat);
FileSize = (t_offset)((filestat.st_mode & S_IFDIR) ? 0 : sim_fsize_name_ex (FileName)); FileSize = (t_offset)((filestat.st_mode & S_IFDIR) ? 0 : sim_fsize_name_ex (FileName));
entry (DirName, p_name, FileSize, &filestat, context); entry (DirName, p_name, FileSize, &filestat, context);
free (FileName);
++found_count;
} }
#if defined (HAVE_GLOB) #if defined (HAVE_GLOB)
globfree (&paths); globfree (&paths);
@ -1019,6 +1025,9 @@ if (dir) {
} }
else else
return SCPE_ARG; return SCPE_ARG;
if (found_count)
return SCPE_OK; return SCPE_OK;
else
return SCPE_ARG;
} }
#endif /* !defined(_WIN32) */ #endif /* !defined(_WIN32) */