]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/tcdbm_mingw.patch
ebl Try to compile tokyodbm with mingw
[bacula/bacula] / bacula / patches / testing / tcdbm_mingw.patch
1 Index: tokyocabinet/myconf.h
2 ===================================================================
3 --- tokyocabinet/myconf.h       (révision 7137)
4 +++ tokyocabinet/myconf.h       (copie de travail)
5 @@ -206,13 +206,16 @@
6  #include <unistd.h>
7  #include <sys/types.h>
8  #include <sys/stat.h>
9 -#include <sys/mman.h>
10  #include <sys/time.h>
11 -#include <sys/times.h>
12  #include <fcntl.h>
13  #include <dirent.h>
14 +
15 +#ifndef HAVE_WIN32
16 +#include <sys/mman.h>
17 +#include <sys/times.h>
18  #include <regex.h>
19  #include <glob.h>
20 +#endif
21  
22  #if TCUSEPTHREAD
23  #include <pthread.h>
24 Index: tokyocabinet/tcutil.c
25 ===================================================================
26 --- tokyocabinet/tcutil.c       (révision 7137)
27 +++ tokyocabinet/tcutil.c       (copie de travail)
28 @@ -2271,7 +2271,7 @@
29    return (a < b) ? a : b;
30  }
31  
32 -
33 +#ifndef HAVE_WIN32
34  /* Get a random number as long integer based on uniform distribution. */
35  unsigned long tclrand(void){
36    static unsigned int cnt = 0;
37 @@ -2288,7 +2288,6 @@
38    return (mask ^ cnt++) ^ (unsigned long)rand_r(&seed);
39  }
40  
41 -
42  /* Get a random number as double decimal based on uniform distribution. */
43  double tcdrand(void){
44    return tclrand() / (ULONG_MAX + 0.01);
45 @@ -2300,6 +2299,7 @@
46    assert(sd >= 0.0);
47    return sqrt(-2.0 * log(tcdrand())) * cos(2 * 3.141592653589793 * tcdrand()) * sd + avg;
48  }
49 +#endif
50  
51  
52  /* Compare two strings with case insensitive evaluation. */
53 @@ -2681,7 +2681,7 @@
54    return buf;
55  }
56  
57 -
58 +#ifndef HAVE_WIN32
59  /* Check whether a string matches a regular expression. */
60  bool tcregexmatch(const char *str, const char *regex){
61    assert(str && regex);
62 @@ -2744,7 +2744,22 @@
63    return tcxstrtomalloc(xstr);
64  }
65  
66 +#endif
67  
68 +#ifdef HAVE_WIN32
69 +
70 +struct timezone {
71 +   int tz_minuteswest; /* minutes à l'ouest de Greenwich  */
72 +   int tz_dsttime;     /* type de changement horaire      */
73 +};
74 +
75 +int gettimeofday(struct timeval *tv, struct timezone *tz)
76 +{
77 +   return -1;
78 +}
79 +
80 +#endif
81 +
82  /* Get the time of day in seconds. */
83  double tctime(void){
84    struct timeval tv;
85 @@ -2752,6 +2767,7 @@
86    return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
87  }
88  
89 +#ifndef HAVE_WIN32
90  
91  /* Get the Gregorian calendar of a time. */
92  void tccalendar(int64_t t, int jl, int *yearp, int *monp, int *dayp,
93 @@ -3064,7 +3080,6 @@
94    return 0;
95  }
96  
97 -
98  /* Get the day of week of a date. */
99  int tcdayofweek(int year, int mon, int day){
100    if(mon < 3){
101 @@ -3105,8 +3120,10 @@
102  #endif
103  }
104  
105 +#endif /* HAVE_WIN32 */
106  
107  
108 +
109  /*************************************************************************************************
110   * filesystem utilities
111   *************************************************************************************************/
112 @@ -3115,6 +3132,7 @@
113  #define TCFILEMODE     00644             // permission of a creating file
114  #define TCIOBUFSIZ     16384             // size of an I/O buffer
115  
116 +#ifndef HAVE_WIN32
117  
118  /* Get the canonicalized absolute path of a file. */
119  char *tcrealpath(const char *path){
120 @@ -3124,6 +3142,7 @@
121    return tcstrdup(buf);
122  }
123  
124 +#endif /* HAVE_WIN32 */
125  
126  /* Read whole data of a file. */
127  void *tcreadfile(const char *path, int limit, int *sp){
128 @@ -3251,6 +3270,7 @@
129    return list;
130  }
131  
132 +#ifndef HAVE_WIN32
133  
134  /* Expand a pattern into a list of matched paths. */
135  TCLIST *tcglobpat(const char *pattern){
136 @@ -3267,6 +3287,9 @@
137    return list;
138  }
139  
140 +#else 
141 +#define lstat stat
142 +#endif
143  
144  /* Remove a file or a directory and its sub ones recursively. */
145  bool tcremovelink(const char *path){
146 @@ -3333,6 +3356,7 @@
147  
148  /* Lock a file. */
149  bool tclock(int fd, bool ex, bool nb){
150 +#ifndef HAVE_WIN32
151    assert(fd >= 0);
152    struct flock lock;
153    memset(&lock, 0, sizeof(struct flock));
154 @@ -3344,6 +3368,7 @@
155    while(fcntl(fd, nb ? F_SETLK : F_SETLKW, &lock) == -1){
156      if(errno != EINTR) return false;
157    }
158 +#endif
159    return true;
160  }
161  
162 @@ -5009,6 +5034,122 @@
163    return wp - obuf;;
164  }
165  
166 +#ifdef HAVE_WIN32
167  
168 +#include <windef.h>
169 +#include <winbase.h>
170  
171 +int msync(void *start, size_t length, int flags)
172 +{
173 +   return 0;
174 +}
175 +int fsync(int fd)
176 +{
177 +   return 0;
178 +}
179 +/*
180 + * Emulation of mmap and unmmap for tokyo dbm
181 + */
182 +void *mmap(void *start, size_t length, int prot, int flags,
183 +           int fd, off_t offset)
184 +{
185 +   DWORD fm_access = 0;
186 +   DWORD mv_access = 0;
187 +   HANDLE h;
188 +   HANDLE mv;
189 +
190 +   if (length == 0) {
191 +      return MAP_FAILED;
192 +   }
193 +   if (!fd) {
194 +      return MAP_FAILED;
195 +   }
196 +
197 +   if (flags & PROT_WRITE) {
198 +      fm_access |= PAGE_READWRITE;
199 +   } else if (flags & PROT_READ) {
200 +      fm_access |= PAGE_READONLY;
201 +   }
202 +
203 +   if (flags & PROT_READ) {
204 +      mv_access |= FILE_MAP_READ;
205 +   }
206 +   if (flags & PROT_WRITE) {
207 +      mv_access |= FILE_MAP_WRITE;
208 +   }
209 +
210 +   h = CreateFileMapping((HANDLE)_get_osfhandle (fd),
211 +                         NULL /* security */,
212 +                         fm_access,
213 +                         0 /* MaximumSizeHigh */,
214 +                         0 /* MaximumSizeLow */,
215 +                         NULL /* name of the file mapping object */);
216 +
217 +   if (!h || h == INVALID_HANDLE_VALUE) {
218 +      return MAP_FAILED;
219 +   }
220 +
221 +   mv = MapViewOfFile(h, mv_access,
222 +                      0 /* offset hi */,
223 +                      0 /* offset lo */,
224 +                      length);
225 +   CloseHandle(h);
226 +
227 +   if (!mv || mv == INVALID_HANDLE_VALUE) {
228 +      return MAP_FAILED;
229 +   }
230 +
231 +   return (void *) mv;
232 +}
233 +
234 +int munmap(void *start, size_t length)
235 +{
236 +   if (!start) {
237 +      return -1;
238 +   }
239 +   UnmapViewOfFile(start);
240 +   return 0;
241 +}
242 +
243 +ssize_t pread(int fd, void *buf, size_t count, off_t offset)
244 +{
245 +   __int64 cur_pos;
246 +   ssize_t num_read;
247 +
248 +   if ((cur_pos = _lseeki64(fd, 0, SEEK_CUR)) == (off_t)-1)
249 +      return -1;
250 +
251 +   if (_lseeki64(fd, offset, SEEK_SET) == (off_t)-1)
252 +      return -1;
253 +
254 +   num_read = read(fd, buf, count);
255 +
256 +   if (_lseeki64(fd, cur_pos, SEEK_SET) == (off_t)-1)
257 +      return -1;
258 +
259 +   return num_read;
260 +}
261 +
262 +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
263 +{
264 +   __int64 cur_pos;
265 +   ssize_t num_write;
266 +
267 +   if ((cur_pos = _lseeki64(fd, 0, SEEK_CUR)) == (off_t)-1)
268 +      return -1;
269 +
270 +   if (_lseeki64(fd, offset, SEEK_SET) == (off_t)-1)
271 +      return -1;
272 +
273 +   num_write = write(fd, buf, count);
274 +
275 +   if (_lseeki64(fd, cur_pos, SEEK_SET) == (off_t)-1)
276 +      return -1;
277 +
278 +   return num_write;
279 +}
280 +
281 +#endif
282 +
283 +
284  // END OF FILE
285 Index: tokyocabinet/tcutil.h
286 ===================================================================
287 --- tokyocabinet/tcutil.h       (révision 7137)
288 +++ tokyocabinet/tcutil.h       (copie de travail)
289 @@ -2160,8 +2160,27 @@
290  #define TCMAPRNUM(TC_map) \
291    ((TC_map)->rnum)
292  
293 +#ifdef HAVE_WIN32
294 +#include <sys/types.h>
295  
296 +/* mmap implementation for tokyodbm */
297 +#define PROT_WRITE 0x2             /* Page can be written.  */
298 +#define PROT_READ  0x1             /* page can be read */
299 +#define MAP_SHARED 0x01            /* Share changes.  */
300 +#define MAP_FAILED ((void *) -1)
301 +#define MS_SYNC 0
302  
303 +void *mmap(void *start, size_t length, int prot, int flags,
304 +           int fd, off_t offset);
305 +int munmap(void *start, size_t length);
306 +int msync(void *start, size_t length, int flags);
307 +int fsync(int fd);
308 +ssize_t pread(int fd, void *buf, size_t count, off_t offset);
309 +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset);
310 +
311 +#endif
312 +
313 +
314  __TCUTIL_CLINKAGEEND
315  #endif                                   /* duplication check */
316