diff --git a/src/cdrom/cdrom_image_backend.c b/src/cdrom/cdrom_image_backend.c index 1c5a87821..19968fe2b 100644 --- a/src/cdrom/cdrom_image_backend.c +++ b/src/cdrom/cdrom_image_backend.c @@ -25,8 +25,10 @@ #include #include #include +#include #ifdef _WIN32 # include +# include #else # include #endif @@ -131,6 +133,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 +145,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) || ((stats.st_mode & S_IFMT) == S_IFDIR)); /* Set the function pointers. */ if (!*error) { 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 */ 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*/