Browse Source

Windows fixes

- Moving required memmap stuff to the header

- proper header inclusion for fstat/stat

- #define snprintf
cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
473bff75fe
  1. 6
      io.h
  2. 2
      io_win32.c
  3. 20
      mmap.h
  4. 17
      mmap_win32.c

6
io.h

@ -43,6 +43,12 @@ enum ethash_io_rc {
ETHASH_IO_MEMO_MATCH, ///< DAG file existed and revision/hash matched. No need to do anything ETHASH_IO_MEMO_MATCH, ///< DAG file existed and revision/hash matched. No need to do anything
}; };
// small hack for windows. I don't feel I should use va_args and forward just
// to have this one function properly cross-platform abstracted
#if defined(_WIN32)
#define snprintf(...) sprintf_s(__VA_ARGS__)
#endif
/** /**
* Prepares io for ethash * Prepares io for ethash
* *

2
io_win32.c

@ -23,6 +23,8 @@
#include <direct.h> #include <direct.h>
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
FILE *ethash_fopen(const char *file_name, const char *mode) FILE *ethash_fopen(const char *file_name, const char *mode)
{ {

20
mmap.h

@ -20,8 +20,26 @@
*/ */
#pragma once #pragma once
#if defined(__MINGW32__) || defined(_WIN32) #if defined(__MINGW32__) || defined(_WIN32)
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset); #include <sys/types.h>
#define PROT_READ 0x1
#define PROT_WRITE 0x2
/* This flag is only available in WinXP+ */
#ifdef FILE_MAP_EXECUTE
#define PROT_EXEC 0x4
#else #else
#define PROT_EXEC 0x0
#define FILE_MAP_EXECUTE 0
#endif
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void *) -1)
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
#else // posix, yay! ^_^
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif

17
mmap_win32.c

@ -13,25 +13,8 @@
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
#include <sys/types.h>
#include "mmap.h" #include "mmap.h"
#define PROT_READ 0x1
#define PROT_WRITE 0x2
/* This flag is only available in WinXP+ */
#ifdef FILE_MAP_EXECUTE
#define PROT_EXEC 0x4
#else
#define PROT_EXEC 0x0
#define FILE_MAP_EXECUTE 0
#endif
#define MAP_SHARED 0x01
#define MAP_PRIVATE 0x02
#define MAP_ANONYMOUS 0x20
#define MAP_ANON MAP_ANONYMOUS
#define MAP_FAILED ((void *) -1)
#ifdef __USE_FILE_OFFSET64 #ifdef __USE_FILE_OFFSET64
# define DWORD_HI(x) (x >> 32) # define DWORD_HI(x) (x >> 32)
# define DWORD_LO(x) ((x) & 0xffffffff) # define DWORD_LO(x) ((x) & 0xffffffff)

Loading…
Cancel
Save