1 Index: tokyocabinet/myconf.h
2 ===================================================================
3 --- tokyocabinet/myconf.h (révision 7137)
4 +++ tokyocabinet/myconf.h (copie de travail)
11 -#include <sys/times.h>
16 +#include <sys/mman.h>
17 +#include <sys/times.h>
24 Index: tokyocabinet/tcutil.c
25 ===================================================================
26 --- tokyocabinet/tcutil.c (révision 7137)
27 +++ tokyocabinet/tcutil.c (copie de travail)
29 return (a < b) ? a : b;
34 /* Get a random number as long integer based on uniform distribution. */
35 unsigned long tclrand(void){
36 static unsigned int cnt = 0;
38 return (mask ^ cnt++) ^ (unsigned long)rand_r(&seed);
42 /* Get a random number as double decimal based on uniform distribution. */
44 return tclrand() / (ULONG_MAX + 0.01);
47 return sqrt(-2.0 * log(tcdrand())) * cos(2 * 3.141592653589793 * tcdrand()) * sd + avg;
52 /* Compare two strings with case insensitive evaluation. */
59 /* Check whether a string matches a regular expression. */
60 bool tcregexmatch(const char *str, const char *regex){
62 @@ -2744,7 +2744,22 @@
63 return tcxstrtomalloc(xstr);
71 + int tz_minuteswest; /* minutes à l'ouest de Greenwich */
72 + int tz_dsttime; /* type de changement horaire */
75 +int gettimeofday(struct timeval *tv, struct timezone *tz)
82 /* Get the time of day in seconds. */
86 return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
91 /* Get the Gregorian calendar of a time. */
92 void tccalendar(int64_t t, int jl, int *yearp, int *monp, int *dayp,
98 /* Get the day of week of a date. */
99 int tcdayofweek(int year, int mon, int day){
101 @@ -3105,8 +3120,10 @@
105 +#endif /* HAVE_WIN32 */
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
118 /* Get the canonicalized absolute path of a file. */
119 char *tcrealpath(const char *path){
120 @@ -3124,6 +3142,7 @@
121 return tcstrdup(buf);
124 +#endif /* HAVE_WIN32 */
126 /* Read whole data of a file. */
127 void *tcreadfile(const char *path, int limit, int *sp){
128 @@ -3251,6 +3270,7 @@
134 /* Expand a pattern into a list of matched paths. */
135 TCLIST *tcglobpat(const char *pattern){
136 @@ -3267,6 +3287,9 @@
144 /* Remove a file or a directory and its sub ones recursively. */
145 bool tcremovelink(const char *path){
146 @@ -3333,6 +3356,7 @@
149 bool tclock(int fd, bool ex, bool nb){
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;
162 @@ -5009,6 +5034,122 @@
169 +#include <winbase.h>
171 +int msync(void *start, size_t length, int flags)
180 + * Emulation of mmap and unmmap for tokyo dbm
182 +void *mmap(void *start, size_t length, int prot, int flags,
183 + int fd, off_t offset)
185 + DWORD fm_access = 0;
186 + DWORD mv_access = 0;
197 + if (flags & PROT_WRITE) {
198 + fm_access |= PAGE_READWRITE;
199 + } else if (flags & PROT_READ) {
200 + fm_access |= PAGE_READONLY;
203 + if (flags & PROT_READ) {
204 + mv_access |= FILE_MAP_READ;
206 + if (flags & PROT_WRITE) {
207 + mv_access |= FILE_MAP_WRITE;
210 + h = CreateFileMapping((HANDLE)_get_osfhandle (fd),
211 + NULL /* security */,
213 + 0 /* MaximumSizeHigh */,
214 + 0 /* MaximumSizeLow */,
215 + NULL /* name of the file mapping object */);
217 + if (!h || h == INVALID_HANDLE_VALUE) {
221 + mv = MapViewOfFile(h, mv_access,
227 + if (!mv || mv == INVALID_HANDLE_VALUE) {
231 + return (void *) mv;
234 +int munmap(void *start, size_t length)
239 + UnmapViewOfFile(start);
243 +ssize_t pread(int fd, void *buf, size_t count, off_t offset)
248 + if ((cur_pos = _lseeki64(fd, 0, SEEK_CUR)) == (off_t)-1)
251 + if (_lseeki64(fd, offset, SEEK_SET) == (off_t)-1)
254 + num_read = read(fd, buf, count);
256 + if (_lseeki64(fd, cur_pos, SEEK_SET) == (off_t)-1)
262 +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset)
267 + if ((cur_pos = _lseeki64(fd, 0, SEEK_CUR)) == (off_t)-1)
270 + if (_lseeki64(fd, offset, SEEK_SET) == (off_t)-1)
273 + num_write = write(fd, buf, count);
275 + if (_lseeki64(fd, cur_pos, SEEK_SET) == (off_t)-1)
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) \
294 +#include <sys/types.h>
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)
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);
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);
315 #endif /* duplication check */