half-hearted improvements to Windows compilability

master
leitner 6 years ago
parent 3aef1c2faa
commit 77a2bbd17a

@ -1,6 +1,6 @@
#include "likely.h" #include "likely.h"
#include <stdlib.h> #include <stdlib.h>
#ifndef __MINGW32__ #ifndef _WIN32
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
@ -13,7 +13,7 @@
#endif #endif
static iarray_page* new_page(size_t pagesize) { static iarray_page* new_page(size_t pagesize) {
#ifdef __MINGW32__ #ifdef _WIN32
void* x=malloc(pagesize); void* x=malloc(pagesize);
if (x==0) return 0; if (x==0) return 0;
#else #else
@ -49,7 +49,7 @@ void* iarray_allocate(iarray* ia,size_t pos) {
p=&(*p)->next; p=&(*p)->next;
} }
if (newpage) if (newpage)
#ifdef __MINGW32__ #ifdef _WIN32
free(newpage); free(newpage);
#else #else
munmap(newpage,ia->bytesperpage); munmap(newpage,ia->bytesperpage);

@ -1,14 +1,15 @@
#include <stdlib.h> #include <stdlib.h>
#ifndef __MINGW32__ #ifndef _WIN32
#include <sys/mman.h> #include <sys/mman.h>
#endif #else
#include <unistd.h> #include <unistd.h>
#endif
#include "iarray.h" #include "iarray.h"
static void freechain(iarray_page* p,size_t pagesize) { static void freechain(iarray_page* p,size_t pagesize) {
while (p) { while (p) {
iarray_page* n=p->next; iarray_page* n=p->next;
#ifdef __MINGW32__ #ifdef _WIN32
free(p); free(p);
#else #else
munmap(p,pagesize); munmap(p,pagesize);

@ -11,7 +11,13 @@ static unsigned int fmt_2digits(char* dest,int i) {
size_t fmt_httpdate(char* dest,time_t t) { size_t fmt_httpdate(char* dest,time_t t) {
static const char days[] = "SunMonTueWedThuFriSat"; static const char days[] = "SunMonTueWedThuFriSat";
static const char months[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; 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); struct tm* x=gmtime(&t);
#endif
size_t i; size_t i;
if (dest==0) return 29; if (dest==0) return 29;

@ -9,7 +9,13 @@ static unsigned int fmt_2digits(char* dest,int i) {
} }
size_t fmt_iso8601(char* dest,time_t t) { 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); struct tm* x=gmtime(&t);
#endif
size_t i; size_t i;
if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1; if (dest==0) return sizeof("2014-05-27T19:22:16Z")-1;

@ -1,15 +1,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #ifdef _WIN32
#ifdef __MINGW32__
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#endif
#include "open.h" #include "open.h"
#endif
#include "mmap.h" #include "mmap.h"
char* mmap_private(const char* filename,size_t * filesize) { char* mmap_private(const char* filename,size_t * filesize) {
#ifdef __MINGW32__ #ifdef _WIN32
HANDLE fd,m; HANDLE fd,m;
char* map; 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); fd=CreateFile(filename,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

@ -1,15 +1,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #ifdef _WIN32
#ifdef __MINGW32__
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#endif
#include "open.h" #include "open.h"
#endif
#include "mmap.h" #include "mmap.h"
extern const char* mmap_read(const char* filename,size_t * filesize) { extern const char* mmap_read(const char* filename,size_t * filesize) {
#ifdef __MINGW32__ #ifdef _WIN32
HANDLE fd,m; HANDLE fd,m;
char* map; char* map;
fd=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); fd=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

@ -2,18 +2,17 @@
#define _ATFILE_SOURCE #define _ATFILE_SOURCE
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #ifndef _WIN32
#ifndef __MINGW32__
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/mman.h> #include <sys/mman.h>
#endif
#include "open.h" #include "open.h"
#endif
#include "mmap.h" #include "mmap.h"
extern const char* mmap_readat(const char* filename,size_t * filesize,int dirfd) { extern const char* mmap_readat(const char* filename,size_t * filesize,int dirfd) {
#ifdef __MINGW32__ #ifdef _WIN32
return 0; return 0;
#else #else
int fd=openat(dirfd,filename,O_RDONLY); int fd=openat(dirfd,filename,O_RDONLY);

@ -1,15 +1,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #ifdef _WIN32
#ifdef __MINGW32__
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#endif
#include "open.h" #include "open.h"
#endif
#include "mmap.h" #include "mmap.h"
extern char* mmap_shared(const char* filename,size_t * filesize) { extern char* mmap_shared(const char* filename,size_t * filesize) {
#ifdef __MINGW32__ #ifdef _WIN32
HANDLE fd,m; HANDLE fd,m;
char* map; 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); fd=CreateFile(filename,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);

@ -1,15 +1,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #ifdef _WIN32
#ifdef __MINGW32__
#include <windows.h> #include <windows.h>
#else #else
#include <unistd.h>
#include <sys/mman.h> #include <sys/mman.h>
#endif
#include "open.h" #include "open.h"
#endif
#include "mmap.h" #include "mmap.h"
int mmap_unmap(const char* mapped,size_t maplen) { int mmap_unmap(const char* mapped,size_t maplen) {
#ifdef __MINGW32__ #ifdef _WIN32
(void)maplen; (void)maplen;
return UnmapViewOfFile(mapped)?0:-1; return UnmapViewOfFile(mapped)?0:-1;
#else #else

Loading…
Cancel
Save