From 4f2205a6672a71bbe5b2ee93f02472ef824aec80 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Tue, 24 Feb 2015 11:12:09 +0100 Subject: [PATCH] OS/2 patches by KO Myung-Hun Upstream patch from MAME project --- mongoose.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/mongoose.c b/mongoose.c index 88ccaf3f..978a2051 100644 --- a/mongoose.c +++ b/mongoose.c @@ -124,7 +124,12 @@ typedef struct _stati64 ns_stat_t; #include #include #define closesocket(x) close(x) +#ifndef __OS2__ #define __cdecl +#else +#include +typedef int socklen_t; +#endif #define INVALID_SOCKET (-1) #define to64(x) strtoll(x, NULL, 10) typedef int sock_t; @@ -1579,6 +1584,37 @@ static void *mmap(void *addr, int64_t len, int prot, int flags, int fd, #define MAP_FAILED NULL #define MAP_PRIVATE 0 #define PROT_READ 0 +#elif defined(__OS2__) +static void *mmap(void *addr, int64_t len, int prot, int flags, int fd, + int offset) { + void *p; + + int pos = lseek( fd, 0, SEEK_CUR ); /* Get a current position */ + + if (pos == -1) + return NULL; + + /* Seek to offset offset */ + if (lseek( fd, offset, SEEK_SET) == -1) + return NULL; + + p = malloc(len); + + /* Read in a file */ + if (!p || read(fd, p, len) == -1) { + free(p); + p = NULL; + } + + /* Restore the position */ + lseek(fd, pos, SEEK_SET); + + return p; +} +#define munmap(x, y) free(x) +#define MAP_FAILED NULL +#define MAP_PRIVATE 0 +#define PROT_READ 0 #else #include #endif