From 77a2bbd17aa79296a389cfa3e269a3f7966edefb Mon Sep 17 00:00:00 2001 From: leitner Date: Tue, 23 Apr 2019 13:25:26 +0000 Subject: [PATCH] half-hearted improvements to Windows compilability --- array/iarray_allocate.c | 6 +++--- array/iarray_free.c | 7 ++++--- fmt/fmt_httpdate.c | 6 ++++++ fmt/fmt_iso8601.c | 6 ++++++ mmap/mmap_private.c | 8 ++++---- mmap/mmap_read.c | 8 ++++---- mmap/mmap_readat.c | 7 +++---- mmap/mmap_shared.c | 8 ++++---- mmap/mmap_unmap.c | 8 ++++---- 9 files changed, 38 insertions(+), 26 deletions(-) diff --git a/array/iarray_allocate.c b/array/iarray_allocate.c index e2d85a6..a7bb3d2 100644 --- a/array/iarray_allocate.c +++ b/array/iarray_allocate.c @@ -1,6 +1,6 @@ #include "likely.h" #include -#ifndef __MINGW32__ +#ifndef _WIN32 #include #include #include @@ -13,7 +13,7 @@ #endif static iarray_page* new_page(size_t pagesize) { -#ifdef __MINGW32__ +#ifdef _WIN32 void* x=malloc(pagesize); if (x==0) return 0; #else @@ -49,7 +49,7 @@ void* iarray_allocate(iarray* ia,size_t pos) { p=&(*p)->next; } if (newpage) -#ifdef __MINGW32__ +#ifdef _WIN32 free(newpage); #else munmap(newpage,ia->bytesperpage); diff --git a/array/iarray_free.c b/array/iarray_free.c index 4db4198..f042b30 100644 --- a/array/iarray_free.c +++ b/array/iarray_free.c @@ -1,14 +1,15 @@ #include -#ifndef __MINGW32__ +#ifndef _WIN32 #include -#endif +#else #include +#endif #include "iarray.h" static void freechain(iarray_page* p,size_t pagesize) { while (p) { iarray_page* n=p->next; -#ifdef __MINGW32__ +#ifdef _WIN32 free(p); #else munmap(p,pagesize); diff --git a/fmt/fmt_httpdate.c b/fmt/fmt_httpdate.c index 7ccbe80..0050dc1 100644 --- a/fmt/fmt_httpdate.c +++ b/fmt/fmt_httpdate.c @@ -11,7 +11,13 @@ static unsigned int fmt_2digits(char* dest,int i) { size_t fmt_httpdate(char* dest,time_t t) { static const char days[] = "SunMonTueWedThuFriSat"; static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; +#ifdef _WIN32 + struct tm tmp; + struct tm* x=&tmp; + gmtime_s(&tmp,&t); // can't recover from when this fails +#else struct tm* x=gmtime(&t); +#endif size_t i; if (dest==0) return 29; diff --git a/fmt/fmt_iso8601.c b/fmt/fmt_iso8601.c index 81ede75..6077364 100644 --- a/fmt/fmt_iso8601.c +++ b/fmt/fmt_iso8601.c @@ -9,7 +9,13 @@ static unsigned int fmt_2digits(char* dest,int i) { } size_t fmt_iso8601(char* dest,time_t t) { +#ifdef _WIN32 + struct tm tmp; + struct tm* x=&tmp; + gmtime_s(&tmp,&t); // can't recover from when this fails +#else struct tm* x=gmtime(&t); +#endif size_t i; if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1; diff --git a/mmap/mmap_private.c b/mmap/mmap_private.c index 771ecf9..78dfe64 100644 --- a/mmap/mmap_private.c +++ b/mmap/mmap_private.c @@ -1,15 +1,15 @@ #include -#include -#ifdef __MINGW32__ +#ifdef _WIN32 #include #else +#include #include -#endif #include "open.h" +#endif #include "mmap.h" char* mmap_private(const char* filename,size_t * filesize) { -#ifdef __MINGW32__ +#ifdef _WIN32 HANDLE fd,m; char* map; fd=CreateFile(filename,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); diff --git a/mmap/mmap_read.c b/mmap/mmap_read.c index 1dfc597..3724b22 100644 --- a/mmap/mmap_read.c +++ b/mmap/mmap_read.c @@ -1,15 +1,15 @@ #include -#include -#ifdef __MINGW32__ +#ifdef _WIN32 #include #else +#include #include -#endif #include "open.h" +#endif #include "mmap.h" extern const char* mmap_read(const char* filename,size_t * filesize) { -#ifdef __MINGW32__ +#ifdef _WIN32 HANDLE fd,m; char* map; fd=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); diff --git a/mmap/mmap_readat.c b/mmap/mmap_readat.c index 0503d6b..8cc618d 100644 --- a/mmap/mmap_readat.c +++ b/mmap/mmap_readat.c @@ -2,18 +2,17 @@ #define _ATFILE_SOURCE #include -#include -#ifndef __MINGW32__ +#ifndef _WIN32 #include #include #include #include -#endif #include "open.h" +#endif #include "mmap.h" extern const char* mmap_readat(const char* filename,size_t * filesize,int dirfd) { -#ifdef __MINGW32__ +#ifdef _WIN32 return 0; #else int fd=openat(dirfd,filename,O_RDONLY); diff --git a/mmap/mmap_shared.c b/mmap/mmap_shared.c index 60f1cb1..2da2078 100644 --- a/mmap/mmap_shared.c +++ b/mmap/mmap_shared.c @@ -1,15 +1,15 @@ #include -#include -#ifdef __MINGW32__ +#ifdef _WIN32 #include #else +#include #include -#endif #include "open.h" +#endif #include "mmap.h" extern char* mmap_shared(const char* filename,size_t * filesize) { -#ifdef __MINGW32__ +#ifdef _WIN32 HANDLE fd,m; char* map; fd=CreateFile(filename,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); diff --git a/mmap/mmap_unmap.c b/mmap/mmap_unmap.c index ce8e419..d0a20c4 100644 --- a/mmap/mmap_unmap.c +++ b/mmap/mmap_unmap.c @@ -1,15 +1,15 @@ #include -#include -#ifdef __MINGW32__ +#ifdef _WIN32 #include #else +#include #include -#endif #include "open.h" +#endif #include "mmap.h" int mmap_unmap(const char* mapped,size_t maplen) { -#ifdef __MINGW32__ +#ifdef _WIN32 (void)maplen; return UnmapViewOfFile(mapped)?0:-1; #else