Make the code buildable on MinGW.org (not mingw-w64) and MSYS1.

This commit is contained in:
yksoft1 2020-05-14 23:47:00 +08:00
parent d2cff2838f
commit fa9af3227e
4 changed files with 26 additions and 1 deletions

View File

@ -38,7 +38,11 @@ typedef s32 ptrdiff_t;
#else
#include <stddef.h>
#include <stdint.h>
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
typedef long ssize_t;
#else
typedef ptrdiff_t ssize_t;
#endif
#endif
#endif

View File

@ -30,4 +30,10 @@
#include <PR/libaudio.h>
#include <PR/libultra.h>
#if defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR)
#include <string.h>
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
#define bcopy(s1, s2, n) memmove((s2), (s1), (n))
#endif
#endif

View File

@ -153,7 +153,21 @@ static size_t buf_vbo_num_tris;
static struct GfxWindowManagerAPI *gfx_wapi;
static struct GfxRenderingAPI *gfx_rapi;
#if defined(_WIN32) && !defined(__MINGW64_VERSION_MAJOR)
#include <windows.h>
#define CLOCK_MONOTONIC 0
//https://stackoverflow.com/questions/5404277/porting-clock-gettime-to-windows
struct timespec { long tv_sec; long tv_nsec; }; //header part
int clock_gettime(int arg, struct timespec *spec) //C-file part
{ __int64 wintime; GetSystemTimeAsFileTime((FILETIME*)&wintime);
wintime -=116444736000000000LL; //1jan1601 to 1jan1970
spec->tv_sec =wintime / 10000000LL; //seconds
spec->tv_nsec =wintime % 10000000LL*100; //nano-seconds
return 0;
}
#else
#include <time.h>
#endif
static unsigned long get_time(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);

View File

@ -7,8 +7,9 @@
// printing size_t varies by compiler
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <windows.h>
#define SIZE_T_FORMAT "%Iu"
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#define realpath(N,R) _fullpath((R),(N),MAX_PATH)
#else
#define SIZE_T_FORMAT "%zu"
#endif