mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Move some MSVC-specific defines to platform.h
This commit is contained in:
@@ -32,4 +32,11 @@
|
|||||||
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* MSVC doesn't use POSIX types or defines for `read` */
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
# define STDIN_FILENO 0
|
||||||
|
# define ssize_t int
|
||||||
|
# define SSIZE_MAX INT_MAX
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* RGBDS_PLATFORM_H */
|
#endif /* RGBDS_PLATFORM_H */
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "extern/utf8decoder.h"
|
#include "extern/utf8decoder.h"
|
||||||
#include "platform.h" /* For `mmap` */
|
#include "platform.h" /* For `ssize_t` */
|
||||||
|
|
||||||
#include "asm/asm.h"
|
#include "asm/asm.h"
|
||||||
#include "asm/lexer.h"
|
#include "asm/lexer.h"
|
||||||
@@ -42,6 +42,47 @@
|
|||||||
#define dbgPrint(...)
|
#define dbgPrint(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Neither MSVC nor MinGW provide `mmap` */
|
||||||
|
#if defined(_MSC_VER) || defined(__MINGW32__)
|
||||||
|
# include <windows.h>
|
||||||
|
# include <fileapi.h>
|
||||||
|
# include <winbase.h>
|
||||||
|
# define MAP_FAILED NULL
|
||||||
|
# define mapFile(ptr, fd, path, size) do { \
|
||||||
|
(ptr) = MAP_FAILED; \
|
||||||
|
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
|
||||||
|
FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_RANDOM_ACCESS, NULL); \
|
||||||
|
HANDLE mappingObj; \
|
||||||
|
\
|
||||||
|
if (file == INVALID_HANDLE_VALUE) \
|
||||||
|
break; \
|
||||||
|
mappingObj = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL); \
|
||||||
|
if (mappingObj != INVALID_HANDLE_VALUE) \
|
||||||
|
(ptr) = MapViewOfFile(mappingObj, FILE_MAP_READ, 0, 0, 0); \
|
||||||
|
CloseHandle(mappingObj); \
|
||||||
|
CloseHandle(file); \
|
||||||
|
} while (0)
|
||||||
|
# define munmap(ptr, size) UnmapViewOfFile((ptr))
|
||||||
|
|
||||||
|
#else /* defined(_MSC_VER) || defined(__MINGW32__) */
|
||||||
|
|
||||||
|
# include <sys/mman.h>
|
||||||
|
# define mapFile(ptr, fd, path, size) do { \
|
||||||
|
(ptr) = mmap(NULL, (size), PROT_READ, MAP_PRIVATE, (fd), 0); \
|
||||||
|
\
|
||||||
|
if ((ptr) == MAP_FAILED && errno == ENOTSUP) { \
|
||||||
|
/*
|
||||||
|
* The implementation may not support MAP_PRIVATE; try again with MAP_SHARED
|
||||||
|
* instead, offering, I believe, weaker guarantees about external modifications to
|
||||||
|
* the file while reading it. That's still better than not opening it at all, though
|
||||||
|
*/ \
|
||||||
|
if (verbose) \
|
||||||
|
printf("mmap(%s, MAP_PRIVATE) failed, retrying with MAP_SHARED\n", path); \
|
||||||
|
(ptr) = mmap(NULL, (size), PROT_READ, MAP_SHARED, (fd), 0); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#endif /* !( defined(_MSC_VER) || defined(__MINGW32__) ) */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Identifiers that are also keywords are listed here. This ONLY applies to ones
|
* Identifiers that are also keywords are listed here. This ONLY applies to ones
|
||||||
* that would normally be matched as identifiers! Check out `yylex_NORMAL` to
|
* that would normally be matched as identifiers! Check out `yylex_NORMAL` to
|
||||||
@@ -313,48 +354,6 @@ static void initState(struct LexerState *state)
|
|||||||
state->expansionOfs = 0;
|
state->expansionOfs = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Neither MSVC nor MinGW provide `mmap` */
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW32__)
|
|
||||||
# include <windows.h>
|
|
||||||
# include <fileapi.h>
|
|
||||||
# include <winbase.h>
|
|
||||||
# define MAP_FAILED NULL
|
|
||||||
# define mapFile(ptr, fd, path, size) do { \
|
|
||||||
(ptr) = MAP_FAILED; \
|
|
||||||
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, \
|
|
||||||
FILE_FLAG_POSIX_SEMANTICS | FILE_FLAG_RANDOM_ACCESS, NULL); \
|
|
||||||
HANDLE mappingObj; \
|
|
||||||
\
|
|
||||||
if (file == INVALID_HANDLE_VALUE) \
|
|
||||||
break; \
|
|
||||||
mappingObj = CreateFileMappingA(file, NULL, PAGE_READONLY, 0, 0, NULL); \
|
|
||||||
if (mappingObj != INVALID_HANDLE_VALUE) \
|
|
||||||
(ptr) = MapViewOfFile(mappingObj, FILE_MAP_READ, 0, 0, 0); \
|
|
||||||
CloseHandle(mappingObj); \
|
|
||||||
CloseHandle(file); \
|
|
||||||
} while (0)
|
|
||||||
# define munmap(ptr, size) UnmapViewOfFile((ptr))
|
|
||||||
|
|
||||||
#else /* defined(_MSC_VER) || defined(__MINGW32__) */
|
|
||||||
|
|
||||||
# include <sys/mman.h>
|
|
||||||
# define mapFile(ptr, fd, path, size) do { \
|
|
||||||
(ptr) = mmap(NULL, (size), PROT_READ, MAP_PRIVATE, (fd), 0); \
|
|
||||||
\
|
|
||||||
if ((ptr) == MAP_FAILED && errno == ENOTSUP) { \
|
|
||||||
/*
|
|
||||||
* The implementation may not support MAP_PRIVATE; try again with MAP_SHARED
|
|
||||||
* instead, offering, I believe, weaker guarantees about external
|
|
||||||
* modifications to the file while reading it. That's still better than not
|
|
||||||
* opening it at all, though.
|
|
||||||
*/ \
|
|
||||||
if (verbose) \
|
|
||||||
printf("mmap(%s, MAP_PRIVATE) failed, retrying with MAP_SHARED\n", path); \
|
|
||||||
(ptr) = mmap(NULL, (size), PROT_READ, MAP_SHARED, (fd), 0); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
#endif /* !( defined(_MSC_VER) || defined(__MINGW32__) ) */
|
|
||||||
|
|
||||||
struct LexerState *lexer_OpenFile(char const *path)
|
struct LexerState *lexer_OpenFile(char const *path)
|
||||||
{
|
{
|
||||||
dbgPrint("Opening file \"%s\"\n", path);
|
dbgPrint("Opening file \"%s\"\n", path);
|
||||||
|
|||||||
Reference in New Issue
Block a user