3 * compatibility wrappers
5 * Created by Arno Bakker, Victor Grishchenko
6 * Copyright 2009-2012 TECHNISCHE UNIVERSITEIT DELFT. All rights reserved.
10 #define SWIFT_COMPAT_H
13 typedef unsigned char uint8_t;
14 typedef signed char int8_t;
15 typedef unsigned short uint16_t;
16 typedef short int16_t;
17 typedef unsigned int uint32_t;
19 typedef __int64 int64_t;
20 typedef unsigned __int64 uint64_t;
29 #include <xutility> // for std::min/max
32 #include <arpa/inet.h>
33 #include <sys/select.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
48 #include "getopt_win.h"
54 #define open(a,b,c) _open(a,b,c)
55 #define strcasecmp stricmp
56 #define strtok_r strtok_s
57 #define stat(a,b) _stat(a,b)
60 #define S_IRUSR _S_IREAD
63 #define S_IWUSR _S_IWRITE
66 #define S_IRGRP _S_IREAD
69 #define S_IROTH _S_IREAD
73 typedef char* setsockoptptr_t;
74 typedef int socklen_t;
76 typedef void* setsockoptptr_t;
79 // libevent2 assumes WIN32 is defined
83 #include <event2/util.h>
86 #define INVALID_SOCKET -1
91 #define LONG_MAX numeric_limits<int>::max()
95 // log2 is C99 which is not fully supported by MS VS
96 #define log2(x) (log(x)/log(2.0))
100 // Arno, 2012-01-05: Handle 64-bit size_t & printf+scanf
101 #if SIZE_MAX > UINT_MAX
102 #define PRISIZET "%llu"
104 #define PRISIZET "%lu"
109 /** tint is the time integer type; microsecond-precise. */
110 typedef int64_t tint;
111 #define TINT_HOUR ((swift::tint)1000000*60*60)
112 #define TINT_MIN ((swift::tint)1000000*60)
113 #define TINT_SEC ((swift::tint)1000000)
114 #define TINT_MSEC ((swift::tint)1000)
115 #define TINT_uSEC ((swift::tint)1)
116 #define TINT_NEVER ((swift::tint)0x3fffffffffffffffLL)
119 #define tintabs _abs64
121 #define tintabs ::abs
130 int64_t file_size (int fd);
132 int file_seek (int fd, int64_t offset);
134 int file_resize (int fd, int64_t new_size);
136 void* memory_map (int fd, size_t size=0);
137 void memory_unmap (int fd, void*, size_t size);
139 void print_error (const char* msg);
143 /** UNIX pread approximation. Does change file pointer. Is not thread-safe */
144 size_t pread(int fildes, void *buf, size_t nbyte, __int64 offset); // off_t not 64-bit dynamically on Win32
146 /** UNIX pwrite approximation. Does change file pointer. Is not thread-safe */
147 size_t pwrite(int fildes, const void *buf, size_t nbyte, __int64 offset);
149 int inet_aton(const char *cp, struct in_addr *inp);
153 std::string gettmpdir(void);
157 bool make_socket_nonblocking(evutil_socket_t s);
159 bool close_socket (evutil_socket_t sock);
161 struct timeval* tint2tv (tint t);