From d131f66c40b472d5a7ea5635ce5abdd083353741 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 30 Dec 2019 13:12:41 -0800 Subject: [PATCH] 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. --- sim_fio.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/sim_fio.c b/sim_fio.c index 6fef8ea9..44ccea44 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -953,6 +953,7 @@ glob_t paths; #else DIR *dir; #endif +int found_count = 0; struct stat filestat; char *c; char DirName[PATH_MAX + 1], WholeName[PATH_MAX + 1], WildName[PATH_MAX + 1]; @@ -982,7 +983,7 @@ if (dir) { struct dirent *ent; #endif t_offset FileSize; - char FileName[PATH_MAX + 1]; + char *FileName; const char *MatchName = 1 + strrchr (cptr, '/'); char *p_name; struct tm *local; @@ -992,24 +993,29 @@ if (dir) { #if defined (HAVE_GLOB) for (i=0; id_name, 0)) continue; -#else - /* only match exact name without fnmatch support */ - if (strcmp(MatchName, ent->d_name) != 0) +#else /* !defined (HAVE_FNMATCH) */ + /* only match all names or exact name without fnmatch support */ + if ((strcmp(MatchName, "*") != 0) && + (strcmp(MatchName, ent->d_name) != 0)) continue; -#endif +#endif /* defined (HAVE_FNMATCH) */ + FileName = (char *)malloc (1 + strlen (DirName) + strlen (ent->d_name)); sprintf (FileName, "%s%s", DirName, ent->d_name); -#endif +#endif /* defined (HAVE_GLOB) */ p_name = FileName + strlen (DirName); memset (&filestat, 0, sizeof (filestat)); (void)stat (FileName, &filestat); FileSize = (t_offset)((filestat.st_mode & S_IFDIR) ? 0 : sim_fsize_name_ex (FileName)); entry (DirName, p_name, FileSize, &filestat, context); + free (FileName); + ++found_count; } #if defined (HAVE_GLOB) globfree (&paths); @@ -1019,6 +1025,9 @@ if (dir) { } else return SCPE_ARG; -return SCPE_OK; +if (found_count) + return SCPE_OK; +else + return SCPE_ARG; } #endif /* !defined(_WIN32) */