From 5409364cf2e6176e651003bc8c802b2fd16d5aa1 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 18 Oct 2022 10:58:42 -0400 Subject: [PATCH 1/4] 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) { From 2d12f0d174ec63106704c9aa715e6748328a79c2 Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 18 Oct 2022 11:00:15 -0400 Subject: [PATCH 2/4] viso: use custom POSIX dir implementation on windows, otherwise use dir.h --- src/include/86box/plat_dir.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/include/86box/plat_dir.h b/src/include/86box/plat_dir.h index 73c33eebf..7a7876ebb 100644 --- a/src/include/86box/plat_dir.h +++ b/src/include/86box/plat_dir.h @@ -17,6 +17,8 @@ #ifndef PLAT_DIR_H #define PLAT_DIR_H +/* Windows needs the POSIX re-implementations */ +#if defined(_WIN32) #ifdef _MAX_FNAME # define MAXNAMLEN _MAX_FNAME #else @@ -63,5 +65,10 @@ extern void seekdir(DIR *, long); extern int closedir(DIR *); #define rewinddir(dirp) seekdir(dirp, 0L) +#else +/* On linux and macOS, use the standard functions and types */ +#include +#endif + #endif /*PLAT_DIR_H*/ From f7c11a94e922ad8772ec382ed36efbf73b79d33e Mon Sep 17 00:00:00 2001 From: ts-korhonen Date: Tue, 18 Oct 2022 20:44:09 +0300 Subject: [PATCH 3/4] Fix windows clang+vcpkg build. --- src/cdrom/cdrom_image_backend.c | 1 + src/cdrom/cdrom_image_viso.c | 4 ++++ src/include/86box/plat.h | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index 1c5a87821..582f9d1d6 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -27,6 +27,7 @@ #include #ifdef _WIN32 # include +# include #else # include #endif diff --git a/src/cdrom/cdrom_image_viso.c b/src/cdrom/cdrom_image_viso.c index e529bdb96..7d40deb26 100644 --- a/src/cdrom/cdrom_image_viso.c +++ b/src/cdrom/cdrom_image_viso.c @@ -38,6 +38,10 @@ #include <86box/nvr.h> // clang-format on +#ifndef S_ISDIR +# define S_ISDIR(m) (((m) &S_IFMT) == S_IFDIR) +#endif + #define VISO_SKIP(p, n) \ { \ memset(p, 0x00, n); \ diff --git a/src/include/86box/plat.h b/src/include/86box/plat.h index 1c17d50bd..aa01ac129 100644 --- a/src/include/86box/plat.h +++ b/src/include/86box/plat.h @@ -76,6 +76,10 @@ extern "C" { # define atomic_bool_t atomic_bool #endif +#if defined(_MSC_VER) +# define ssize_t intptr_t +#endif + /* Global variables residing in the platform module. */ extern int dopause, /* system is paused */ mouse_capture; /* mouse is captured in app */ From b81d4170f9b89b5cc03e33ce82d6caee40fa11ea Mon Sep 17 00:00:00 2001 From: cold-brewed Date: Tue, 18 Oct 2022 14:20:33 -0400 Subject: [PATCH 4/4] viso: Check for directory without S_ISDIR macro for msvc --- src/cdrom/cdrom_image_backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index 44c9efa7a..2ec7a5d03 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -148,7 +148,7 @@ bin_init(const char *filename, int *error) /* Use a blank structure if stat failed. */ memset(&stats, 0, sizeof(struct stat)); } - *error = ((tf->file == NULL) || (S_ISDIR(stats.st_mode))); + *error = ((tf->file == NULL) || ((stats.st_mode & S_IFMT) == S_IFDIR)); /* Set the function pointers. */ if (!*error) {