1/*- 2 * $Id$ 3 * 4 * The following provides the information necessary to build Berkeley 5 * DB on native Windows, and other Windows environments such as MinGW. 6 */ 7 8/* 9 * Windows NT 4.0 and later required for the replication manager. 10 */ 11#ifdef HAVE_REPLICATION_THREADS 12#define _WIN32_WINNT 0x0400 13#endif 14 15#ifndef DB_WINCE 16#include <sys/types.h> 17#include <sys/stat.h> 18#include <sys/timeb.h> 19 20#include <direct.h> 21#include <fcntl.h> 22#include <io.h> 23#include <limits.h> 24#include <memory.h> 25#include <process.h> 26#include <signal.h> 27#endif /* DB_WINCE */ 28 29#include <errno.h> 30#include <stdio.h> 31#include <stdlib.h> 32#include <tchar.h> 33#include <time.h> 34 35/* 36 * To build Tcl interface libraries, the include path must be configured to 37 * use the directory containing <tcl.h>, usually the include directory in 38 * the Tcl distribution. 39 */ 40#ifdef DB_TCL_SUPPORT 41#include <tcl.h> 42#endif 43 44#define WIN32_LEAN_AND_MEAN 45#include <windows.h> 46#include <winsock2.h> 47 48#ifdef HAVE_GETADDRINFO 49/* 50 * Need explicit includes for IPv6 support on Windows. Both are necessary to 51 * ensure that pre WinXP versions have an implementation of the getaddrinfo API. 52 */ 53#include <ws2tcpip.h> 54#include <wspiapi.h> 55#endif 56 57/* 58 * Microsoft's C runtime library has fsync, getcwd, getpid, snprintf and 59 * vsnprintf, but under different names. 60 */ 61#define fsync _commit 62 63#ifndef DB_WINCE 64#define getcwd(buf, size) _getcwd(buf, size) 65#endif 66#define getpid GetCurrentProcessId 67#define snprintf _snprintf 68#define strcasecmp _stricmp 69#define strncasecmp _strnicmp 70#define vsnprintf _vsnprintf 71 72#define h_errno WSAGetLastError() 73 74/* 75 * Win32 does not have getopt. 76 * 77 * The externs are here, instead of using db_config.h and clib_port.h, because 78 * that approach changes function names to BDB specific names, and the example 79 * programs use getopt and can't use BDB specific names. 80 */ 81#if defined(__cplusplus) 82extern "C" { 83#endif 84extern int getopt(int, char * const *, const char *); 85#if defined(__cplusplus) 86} 87#endif 88 89/* 90 * Microsoft's compiler _doesn't_ define __STDC__ unless you invoke it with 91 * arguments turning OFF all vendor extensions. Even more unfortunately, if 92 * we do that, it fails to parse windows.h!!!!! So, we define __STDC__ here, 93 * after windows.h comes in. Note: the compiler knows we've defined it, and 94 * starts enforcing strict ANSI compliance from this point on. 95 */ 96#ifndef __STDC__ 97#define __STDC__ 1 98#endif 99 100#ifdef _UNICODE 101#define TO_TSTRING(dbenv, s, ts, ret) do { \ 102 int __len = (int)strlen(s) + 1; \ 103 ts = NULL; \ 104 if ((ret = __os_malloc((dbenv), \ 105 __len * sizeof(_TCHAR), &(ts))) == 0 && \ 106 MultiByteToWideChar(CP_UTF8, 0, \ 107 (s), -1, (ts), __len) == 0) \ 108 ret = __os_posix_err(__os_get_syserr()); \ 109 } while (0) 110 111#define FROM_TSTRING(dbenv, ts, s, ret) { \ 112 int __len = WideCharToMultiByte(CP_UTF8, 0, ts, -1, \ 113 NULL, 0, NULL, NULL); \ 114 s = NULL; \ 115 if ((ret = __os_malloc((dbenv), __len, &(s))) == 0 && \ 116 WideCharToMultiByte(CP_UTF8, 0, \ 117 (ts), -1, (s), __len, NULL, NULL) == 0) \ 118 ret = __os_posix_err(__os_get_syserr()); \ 119 } while (0) 120 121#define FREE_STRING(dbenv, s) do { \ 122 if ((s) != NULL) { \ 123 __os_free((dbenv), (s)); \ 124 (s) = NULL; \ 125 } \ 126 } while (0) 127 128#else 129#define TO_TSTRING(dbenv, s, ts, ret) (ret) = 0, (ts) = (_TCHAR *)(s) 130#define FROM_TSTRING(dbenv, ts, s, ret) (ret) = 0, (s) = (char *)(ts) 131#define FREE_STRING(dbenv, ts) 132#endif 133 134#ifndef INVALID_HANDLE_VALUE 135#define INVALID_HANDLE_VALUE ((HANDLE)-1) 136#endif 137 138#ifndef INVALID_FILE_ATTRIBUTES 139#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) 140#endif 141 142#ifndef INVALID_SET_FILE_POINTER 143#define INVALID_SET_FILE_POINTER ((DWORD)-1) 144#endif 145