From: Eric Bollengier Date: Fri, 27 Jun 2008 15:12:27 +0000 (+0000) Subject: ebl update tokyodbm for mingw X-Git-Tag: Release-3.0.0~1221 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=941568a1cfa8848b269d64fa5a1dcda68dae96b6;p=bacula%2Fbacula ebl update tokyodbm for mingw git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@7246 91ce42f0-d328-0410-95d8-f526ca767f89 --- diff --git a/bacula/src/lib/tokyocabinet/compat.c b/bacula/src/lib/tokyocabinet/compat.c new file mode 100644 index 0000000000..0c6bec0e6a --- /dev/null +++ b/bacula/src/lib/tokyocabinet/compat.c @@ -0,0 +1,248 @@ +/************************************************************************************************* + * The compat WIN32 API of Tokyo Cabinet + * Copyright (C) 2006-2008 Mikio Hirabayashi + * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * You should have received a copy of the GNU Lesser General Public License along with Tokyo + * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA. + *************************************************************************************************/ + +#ifdef HAVE_WIN32 + +#include "tcutil.h" +#include "myconf.h" +#include +#include + +int msync(void *start, size_t length, int flags) +{ + return 0; +} +int fsync(int fd) +{ + return 0; +} + +/* + * Keep track of HANDLE for CreateView + */ + +struct mmap_priv +{ + HANDLE h; + HANDLE mv; +}; + +static TCLIST *mmap_list=NULL; + +static void mmap_register(HANDLE h, HANDLE mv) +{ + struct mmap_priv *priv; +/* + if (!tcglobalmutexlock()) { + return; + } +*/ + if (!mmap_list) { + mmap_list = tclistnew(); + } + + priv = tcmalloc(sizeof(struct mmap_priv)); + priv->h = h; + priv->mv = mv; + tclistpush(mmap_list, priv, sizeof(priv)); +/* + tcglobalmutexunlock(); +*/ +} + +static HANDLE mmap_unregister(HANDLE mv) +{ + HANDLE h=NULL; + struct mmap_priv *priv; + int i, max, size; + int nok=1; +/* + if (!tcglobalmutexlock()) { + return NULL; + } +*/ + max = tclistnum(mmap_list); + for(i=0; nok && imv == mv)) { + tclistremove(mmap_list, i, &size); + h = priv->h; + tcfree(mmap_list); + nok=0; + } + } +/* + tcglobalmutexunlock(); +*/ + return h; +} + + +/* + * Emulation of mmap and unmmap for tokyo dbm + */ +void *mmap(void *start, size_t length, int prot, int flags, + int fd, off_t offset) +{ + DWORD fm_access = 0; + DWORD mv_access = 0; + HANDLE h; + HANDLE mv; + + if (length == 0) { + return MAP_FAILED; + } + if (!fd) { + return MAP_FAILED; + } + + if (flags & PROT_WRITE) { + fm_access |= PAGE_READWRITE; + } else if (flags & PROT_READ) { + fm_access |= PAGE_READONLY; + } + + if (flags & PROT_READ) { + mv_access |= FILE_MAP_READ; + } + if (flags & PROT_WRITE) { + mv_access |= FILE_MAP_WRITE; + } + + h = CreateFileMapping((HANDLE)_get_osfhandle (fd), + NULL /* security */, + fm_access, + 0 /* MaximumSizeHigh */, + 0 /* MaximumSizeLow */, + NULL /* name of the file mapping object */); + + if (!h || h == INVALID_HANDLE_VALUE) { + return MAP_FAILED; + } + + mv = MapViewOfFile(h, mv_access, + 0 /* offset hi */, + 0 /* offset lo */, + length); + if (!mv || mv == INVALID_HANDLE_VALUE) { + CloseHandle(h); + return MAP_FAILED; + } + + mmap_register(h, mv); + return (void *) mv; +} + +int munmap(void *start, size_t length) +{ + HANDLE h; + if (!start) { + return -1; + } + h = mmap_unregister(start); + UnmapViewOfFile(start); + CloseHandle(h); + return 0; +} + +int regcomp(regex_t *preg, const char *regex, int cflags) +{ + return 0; +} + +int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags) +{ + return 0; +} + +size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) +{ + *errbuf = 0; + return 0; +} +/* +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + return -1; +} +*/ +void regfree(regex_t *preg) +{ +} + +int glob(const char *pattern, int flags, + int (*errfunc) (const char *epath, int eerrno), + glob_t *pglob) +{ + return GLOB_NOMATCH; +} +void globfree(glob_t *pglob) +{ +} + +char *realpath(const char *path, char *resolved_path) +{ + strcpy(resolved_path, path); + return resolved_path; +} + +/* +int rand_r(unsigned int *seedp) +{ + *seedp = *seedp * 1103515245 + 12345; + return((unsigned)(*seedp/65536) % 32768); +} +*/ + +/* read from a file descriptor at a given offset */ +ssize_t pread(int fd, void *buf, size_t count, off_t offset) +{ + __int64 cur_pos; + ssize_t num_read; + + if ((cur_pos = _lseeki64(fd, 0, SEEK_CUR)) == (off_t)-1) + return -1; + + if (_lseeki64(fd, offset, SEEK_SET) == (off_t)-1) + return -1; + + num_read = read(fd, buf, count); + + if (_lseeki64(fd, cur_pos, SEEK_SET) == (off_t)-1) + return -1; + + return num_read; +} + +/* write to a file descriptor at a given offset */ +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) +{ + __int64 cur_pos; + ssize_t num_write; + + if ((cur_pos = _lseeki64(fd, 0, SEEK_CUR)) == (off_t)-1) + return -1; + + if (_lseeki64(fd, offset, SEEK_SET) == (off_t)-1) + return -1; + + num_write = write(fd, buf, count); + + if (_lseeki64(fd, cur_pos, SEEK_SET) == (off_t)-1) + return -1; + + return num_write; +} + +#endif diff --git a/bacula/src/lib/tokyocabinet/compat.h b/bacula/src/lib/tokyocabinet/compat.h new file mode 100644 index 0000000000..4ea0a3098d --- /dev/null +++ b/bacula/src/lib/tokyocabinet/compat.h @@ -0,0 +1,89 @@ +/************************************************************************************************* + * The win32 compat API of Tokyo Cabinet + * Copyright (C) 2006-2008 Mikio Hirabayashi + * + * Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of + * the GNU Lesser General Public License as published by the Free Software Foundation; either + * version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * You should have received a copy of the GNU Lesser General Public License along with Tokyo + * Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA. + *************************************************************************************************/ + +#ifndef COMPAT_H +#define COMPAT_H + +#ifdef HAVE_WIN32 +#include + +typedef int regoff_t; + +typedef struct { + regoff_t rm_so; + regoff_t rm_eo; +} regmatch_t; + +typedef struct { + +} regex_t; + +#define REG_EXTENDED 0 +#define REG_NOSUB 0 +#define REG_ICASE 0 +#define REG_NOTBOL 0 +int regcomp(regex_t *preg, const char *regex, int cflags); +int regexec(const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags); +size_t regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size); +void regfree(regex_t *preg); + + +/* mmap implementation for tokyodbm */ +#define PROT_WRITE 0x2 /* Page can be written. */ +#define PROT_READ 0x1 /* page can be read */ +#define MAP_SHARED 0x01 /* Share changes. */ +#define MAP_FAILED ((void *) -1) +#define MS_SYNC 0 + +void *mmap(void *start, size_t length, int prot, int flags, + int fd, off_t offset); +int munmap(void *start, size_t length); +int msync(void *start, size_t length, int flags); +int fsync(int fd); +ssize_t pread(int fd, void *buf, size_t count, off_t offset); +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); +int rand_r(int *seedp); + +/* +struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; + +int gettimeofday(struct timeval *tv, struct timezone *tz); +*/ + +typedef struct { + size_t gl_pathc; /* Count of paths matched so far */ + char **gl_pathv; /* List of matched pathnames. */ + size_t gl_offs; /* Slots to reserve in ‘gl_pathv’. */ +} glob_t; + +int glob(const char *pattern, int flags, + int (*errfunc) (const char *epath, int eerrno), + glob_t *pglob); + +void globfree(glob_t *pglob); + +#define GLOB_ERR 0 +#define GLOB_NOSORT 0 +#define GLOB_NOMATCH 0 + +char *realpath(const char *path, char *resolved_path); + +#define lstat stat + +#endif /* HAVE_WIN32 */ +#endif /* !COMPAT_H */