From 5409364cf2e6176e651003bc8c802b2fd16d5aa1 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 18 Oct 2022 10:58:42 -0400 Subject: [PATCH] viso: use stat to check for directory in bin_init --- src/cdrom/cdrom_image_backend.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index 1c5a87821..44c9efa7a 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef _WIN32 # include #else @@ -131,6 +132,7 @@ static track_file_t * bin_init(const char *filename, int *error) { track_file_t *tf = (track_file_t *) malloc(sizeof(track_file_t)); + struct stat stats; if (tf == NULL) { *error = 1; @@ -142,7 +144,11 @@ bin_init(const char *filename, int *error) tf->file = plat_fopen64(tf->fn, "rb"); cdrom_image_backend_log("CDROM: binary_open(%s) = %08lx\n", tf->fn, tf->file); - *error = (tf->file == NULL); + if (stat(tf->fn, &stats) != 0) { + /* Use a blank structure if stat failed. */ + memset(&stats, 0, sizeof(struct stat)); + } + *error = ((tf->file == NULL) || (S_ISDIR(stats.st_mode))); /* Set the function pointers. */ if (!*error) {