00001 /* Copyright (C) 2000 MySQL AB 00002 00003 This program is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU General Public License as published by 00005 the Free Software Foundation; either version 2 of the License, or 00006 (at your option) any later version. 00007 00008 This program is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 GNU General Public License for more details. 00012 00013 You should have received a copy of the GNU General Public License 00014 along with this program; if not, write to the Free Software 00015 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 00016 00017 /* Defines for Win32 to make it compatible for MySQL */ 00018 00019 #ifdef __WIN2000__ 00020 /* We have to do this define before including windows.h to get the AWE API 00021 functions */ 00022 #define _WIN32_WINNT 0x0500 00023 #endif 00024 00025 #if defined(_MSC_VER) && _MSC_VER >= 1400 00026 /* Avoid endless warnings about sprintf() etc. being unsafe. */ 00027 #define _CRT_SECURE_NO_DEPRECATE 1 00028 #define _USE_32BIT_TIME_T 1 /* force time_t to be 32 bit */ 00029 #endif 00030 00031 #include <sys/locking.h> 00032 #include <windows.h> 00033 #include <math.h> /* Because of rint() */ 00034 #include <fcntl.h> 00035 #include <io.h> 00036 #include <malloc.h> 00037 00038 #define HAVE_SMEM 1 00039 00040 #if defined(_WIN64) || defined(WIN64) 00041 #define SYSTEM_TYPE "Win64" 00042 #elif defined(_WIN32) || defined(WIN32) 00043 #define SYSTEM_TYPE "Win32" 00044 #else 00045 #define SYSTEM_TYPE "Windows" 00046 #endif 00047 00048 #if defined(_M_IA64) 00049 #define MACHINE_TYPE "ia64" 00050 #elif defined(_M_IX86) 00051 #define MACHINE_TYPE "ia32" 00052 #elif defined(_M_ALPHA) 00053 #define MACHINE_TYPE "axp" 00054 #else 00055 #define MACHINE_TYPE "unknown" /* Define to machine type name */ 00056 #endif 00057 00058 #if !(defined(_WIN64) || defined(WIN64)) 00059 #ifndef _WIN32 00060 #define _WIN32 /* Compatible with old source */ 00061 #endif 00062 #ifndef __WIN32__ 00063 #define __WIN32__ 00064 #endif 00065 #endif /* _WIN64 */ 00066 #ifndef __WIN__ 00067 #define __WIN__ /* To make it easier in VC++ */ 00068 #endif 00069 00070 #ifndef MAX_INDEXES 00071 #define MAX_INDEXES 64 00072 #endif 00073 00074 /* File and lock constants */ 00075 #define O_SHARE 0x1000 /* Open file in sharing mode */ 00076 #ifdef __BORLANDC__ 00077 #define F_RDLCK LK_NBLCK /* read lock */ 00078 #define F_WRLCK LK_NBRLCK /* write lock */ 00079 #define F_UNLCK LK_UNLCK /* remove lock(s) */ 00080 #else 00081 #define F_RDLCK _LK_NBLCK /* read lock */ 00082 #define F_WRLCK _LK_NBRLCK /* write lock */ 00083 #define F_UNLCK _LK_UNLCK /* remove lock(s) */ 00084 #endif 00085 00086 #define F_EXCLUSIVE 1 /* We have only exclusive locking */ 00087 #define F_TO_EOF (INT_MAX32/2) /* size for lock of all file */ 00088 #define F_OK 0 /* parameter to access() */ 00089 #define W_OK 2 00090 00091 #define S_IROTH S_IREAD /* for my_lib */ 00092 00093 #ifdef __BORLANDC__ 00094 #define FILE_BINARY O_BINARY /* my_fopen in binary mode */ 00095 #define O_TEMPORARY 0 00096 #define O_SHORT_LIVED 0 00097 #define SH_DENYNO _SH_DENYNO 00098 #else 00099 #define O_BINARY _O_BINARY /* compability with older style names */ 00100 #define FILE_BINARY _O_BINARY /* my_fopen in binary mode */ 00101 #define O_TEMPORARY _O_TEMPORARY 00102 #define O_SHORT_LIVED _O_SHORT_LIVED 00103 #define SH_DENYNO _SH_DENYNO 00104 #endif 00105 #define NO_OPEN_3 /* For my_create() */ 00106 00107 #define SIGQUIT SIGTERM /* No SIGQUIT */ 00108 00109 #undef _REENTRANT /* Crashes something for win32 */ 00110 #undef SAFE_MUTEX /* Can't be used on windows */ 00111 00112 #if defined(_MSC_VER) && _MSC_VER >= 1310 00113 #define LL(A) A##ll 00114 #define ULL(A) A##ull 00115 #else 00116 #define LL(A) ((__int64) A) 00117 #define ULL(A) ((unsigned __int64) A) 00118 #endif 00119 00120 #define LONGLONG_MIN LL(0x8000000000000000) 00121 #define LONGLONG_MAX LL(0x7FFFFFFFFFFFFFFF) 00122 #define ULONGLONG_MAX ULL(0xFFFFFFFFFFFFFFFF) 00123 00124 /* Type information */ 00125 00126 #if !defined(HAVE_UINT) 00127 #undef HAVE_UINT 00128 #define HAVE_UINT 00129 typedef unsigned short ushort; 00130 typedef unsigned int uint; 00131 #endif /* !defined(HAVE_UINT) */ 00132 00133 typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */ 00134 typedef __int64 longlong; 00135 #ifndef HAVE_SIGSET_T 00136 typedef int sigset_t; 00137 #endif 00138 #define longlong_defined 00139 /* 00140 off_t should not be __int64 because of conflicts in header files; 00141 Use my_off_t or os_off_t instead 00142 */ 00143 #ifndef HAVE_OFF_T 00144 typedef long off_t; 00145 #endif 00146 typedef __int64 os_off_t; 00147 #ifdef _WIN64 00148 typedef UINT_PTR rf_SetTimer; 00149 #else 00150 #ifndef HAVE_SIZE_T 00151 typedef unsigned int size_t; 00152 #endif 00153 typedef uint rf_SetTimer; 00154 #endif 00155 00156 #define Socket_defined 00157 #define my_socket SOCKET 00158 #define bool BOOL 00159 #define SIGPIPE SIGINT 00160 #define RETQSORTTYPE void 00161 #define QSORT_TYPE_IS_VOID 00162 #define RETSIGTYPE void 00163 #define SOCKET_SIZE_TYPE int 00164 #define my_socket_defined 00165 #define bool_defined 00166 #define byte_defined 00167 #define HUGE_PTR 00168 #define STDCALL __stdcall /* Used by libmysql.dll */ 00169 #define isnan(X) _isnan(X) 00170 #define finite(X) _finite(X) 00171 00172 #ifndef UNDEF_THREAD_HACK 00173 #define THREAD 00174 #endif 00175 #define VOID_SIGHANDLER 00176 #define SIZEOF_CHAR 1 00177 #define SIZEOF_LONG 4 00178 #define SIZEOF_LONG_LONG 8 00179 #define SIZEOF_OFF_T 8 00180 #ifdef _WIN64 00181 #define SIZEOF_CHARP 8 00182 #else 00183 #define SIZEOF_CHARP 4 00184 #endif 00185 #define HAVE_BROKEN_NETINET_INCLUDES 00186 #ifdef __NT__ 00187 #define HAVE_NAMED_PIPE /* We can only create pipes on NT */ 00188 #endif 00189 00190 /* ERROR is defined in wingdi.h */ 00191 #undef ERROR 00192 00193 /* We need to close files to break connections on shutdown */ 00194 #ifndef SIGNAL_WITH_VIO_CLOSE 00195 #define SIGNAL_WITH_VIO_CLOSE 00196 #endif 00197 00198 /* Use all character sets in MySQL */ 00199 #define USE_MB 1 00200 #define USE_MB_IDENT 1 00201 #define USE_STRCOLL 1 00202 00203 /* All windows servers should support .sym files */ 00204 #undef USE_SYMDIR 00205 #define USE_SYMDIR 00206 00207 /* If LOAD DATA LOCAL INFILE should be enabled by default */ 00208 #define ENABLED_LOCAL_INFILE 1 00209 00210 /* Convert some simple functions to Posix */ 00211 00212 #define my_sigset(A,B) signal((A),(B)) 00213 #define finite(A) _finite(A) 00214 #define sleep(A) Sleep((A)*1000) 00215 #define popen(A,B) _popen((A),(B)) 00216 #define pclose(A) _pclose(A) 00217 00218 #ifndef __BORLANDC__ 00219 #define access(A,B) _access(A,B) 00220 #endif 00221 00222 #if !defined(__cplusplus) 00223 #define inline __inline 00224 #endif /* __cplusplus */ 00225 00226 inline double rint(double nr) 00227 { 00228 double f = floor(nr); 00229 double c = ceil(nr); 00230 return (((c-nr) >= (nr-f)) ? f :c); 00231 } 00232 00233 #ifdef _WIN64 00234 #define ulonglong2double(A) ((double) (ulonglong) (A)) 00235 #define my_off_t2double(A) ((double) (my_off_t) (A)) 00236 00237 #else 00238 inline double ulonglong2double(ulonglong value) 00239 { 00240 longlong nr=(longlong) value; 00241 if (nr >= 0) 00242 return (double) nr; 00243 return (18446744073709551616.0 + (double) nr); 00244 } 00245 #define my_off_t2double(A) ulonglong2double(A) 00246 #endif /* _WIN64 */ 00247 00248 #if SIZEOF_OFF_T > 4 00249 #define lseek(A,B,C) _lseeki64((A),(longlong) (B),(C)) 00250 #define tell(A) _telli64(A) 00251 #endif 00252 00253 #define set_timespec(ABSTIME,SEC) { (ABSTIME).tv_sec=time((time_t*)0) + (time_t) (SEC); (ABSTIME).tv_nsec=0; } 00254 00255 #define STACK_DIRECTION -1 00256 00257 /* Optimized store functions for Intel x86 */ 00258 00259 #ifndef _WIN64 00260 #define sint2korr(A) (*((int16 *) (A))) 00261 #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \ 00262 (((uint32) 255L << 24) | \ 00263 (((uint32) (uchar) (A)[2]) << 16) |\ 00264 (((uint32) (uchar) (A)[1]) << 8) | \ 00265 ((uint32) (uchar) (A)[0])) : \ 00266 (((uint32) (uchar) (A)[2]) << 16) |\ 00267 (((uint32) (uchar) (A)[1]) << 8) | \ 00268 ((uint32) (uchar) (A)[0]))) 00269 #define sint4korr(A) (*((long *) (A))) 00270 #define uint2korr(A) (*((uint16 *) (A))) 00271 /* 00272 ATTENTION ! 00273 00274 Please, note, uint3korr reads 4 bytes (not 3) ! 00275 It means, that you have to provide enough allocated space ! 00276 */ 00277 #define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF) 00278 #define uint4korr(A) (*((unsigned long *) (A))) 00279 #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ 00280 (((uint32) ((uchar) (A)[1])) << 8) +\ 00281 (((uint32) ((uchar) (A)[2])) << 16) +\ 00282 (((uint32) ((uchar) (A)[3])) << 24)) +\ 00283 (((ulonglong) ((uchar) (A)[4])) << 32)) 00284 #define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) + \ 00285 (((uint32) ((uchar) (A)[1])) << 8) + \ 00286 (((uint32) ((uchar) (A)[2])) << 16) + \ 00287 (((uint32) ((uchar) (A)[3])) << 24)) + \ 00288 (((ulonglong) ((uchar) (A)[4])) << 32) + \ 00289 (((ulonglong) ((uchar) (A)[5])) << 40)) 00290 #define uint8korr(A) (*((ulonglong *) (A))) 00291 #define sint8korr(A) (*((longlong *) (A))) 00292 #define int2store(T,A) *((uint16*) (T))= (uint16) (A) 00293 #define int3store(T,A) { *(T)= (uchar) ((A));\ 00294 *(T+1)=(uchar) (((uint) (A) >> 8));\ 00295 *(T+2)=(uchar) (((A) >> 16)); } 00296 #define int4store(T,A) *((long *) (T))= (long) (A) 00297 #define int5store(T,A) { *(T)= (uchar)((A));\ 00298 *((T)+1)=(uchar) (((A) >> 8));\ 00299 *((T)+2)=(uchar) (((A) >> 16));\ 00300 *((T)+3)=(uchar) (((A) >> 24)); \ 00301 *((T)+4)=(uchar) (((A) >> 32)); } 00302 #define int6store(T,A) { *(T) =(uchar)((A)); \ 00303 *((T)+1)=(uchar) (((A) >> 8)); \ 00304 *((T)+2)=(uchar) (((A) >> 16)); \ 00305 *((T)+3)=(uchar) (((A) >> 24)); \ 00306 *((T)+4)=(uchar) (((A) >> 32)); \ 00307 *((T)+5)=(uchar) (((A) >> 40)); } 00308 #define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A) 00309 00310 #define doubleget(V,M) do { *((long *) &V) = *((long*) M); \ 00311 *(((long *) &V)+1) = *(((long*) M)+1); } while(0) 00312 #define doublestore(T,V) do { *((long *) T) = *((long*) &V); \ 00313 *(((long *) T)+1) = *(((long*) &V)+1); } while(0) 00314 #define float4get(V,M) { *((long *) &(V)) = *((long*) (M)); } 00315 #define floatstore(T,V) memcpy((byte*)(T), (byte*)(&V), sizeof(float)) 00316 #define floatget(V,M) memcpy((byte*)(&V), (byte*)(M), sizeof(float)) 00317 #define float8get(V,M) doubleget((V),(M)) 00318 #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float)) 00319 #define float8store(V,M) doublestore((V),(M)) 00320 #endif /* _WIN64 */ 00321 00322 #define HAVE_PERROR 00323 #define HAVE_VFPRINT 00324 #define HAVE_RENAME /* Have rename() as function */ 00325 #define HAVE_BINARY_STREAMS /* Have "b" flag in streams */ 00326 #define HAVE_LONG_JMP /* Have long jump function */ 00327 #define HAVE_LOCKING /* have locking() call */ 00328 #define HAVE_ERRNO_AS_DEFINE /* errno is a define */ 00329 #define HAVE_STDLIB /* everything is include in this file */ 00330 #define HAVE_MEMCPY 00331 #define HAVE_MEMMOVE 00332 #define HAVE_GETCWD 00333 #define HAVE_TELL 00334 #define HAVE_TZNAME 00335 #define HAVE_PUTENV 00336 #define HAVE_SELECT 00337 #define HAVE_SETLOCALE 00338 #define HAVE_SOCKET /* Giangi */ 00339 #define HAVE_FLOAT_H 00340 #define HAVE_LIMITS_H 00341 #define HAVE_STDDEF_H 00342 #define HAVE_RINT /* defined in this file */ 00343 #define NO_FCNTL_NONBLOCK /* No FCNTL */ 00344 #define HAVE_ALLOCA 00345 #define HAVE_STRPBRK 00346 #define HAVE_STRSTR 00347 #define HAVE_COMPRESS 00348 #define HAVE_CREATESEMAPHORE 00349 #define HAVE_ISNAN 00350 #define HAVE_FINITE 00351 #define HAVE_QUERY_CACHE 00352 #define SPRINTF_RETURNS_INT 00353 #define HAVE_SETFILEPOINTER 00354 #define HAVE_VIO_READ_BUFF 00355 #define HAVE_STRNLEN 00356 00357 #define strcasecmp stricmp 00358 #define strncasecmp strnicmp 00359 00360 #ifndef __NT__ 00361 #undef FILE_SHARE_DELETE 00362 #define FILE_SHARE_DELETE 0 /* Not implemented on Win 98/ME */ 00363 #endif 00364 00365 #ifdef NOT_USED 00366 #define HAVE_SNPRINTF /* Gave link error */ 00367 #define _snprintf snprintf 00368 #endif 00369 00370 #ifdef _MSC_VER 00371 #define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */ 00372 #define HAVE_ANSI_INCLUDE 00373 #define HAVE_SYS_UTIME_H 00374 #define HAVE_STRTOUL 00375 #endif 00376 #define my_reinterpret_cast(A) reinterpret_cast <A> 00377 #define my_const_cast(A) const_cast<A> 00378 00379 00380 /* MYSQL OPTIONS */ 00381 00382 #ifdef _CUSTOMCONFIG_ 00383 #include <custom_conf.h> 00384 #else 00385 #define DEFAULT_MYSQL_HOME "c:\\mysql" 00386 #define DATADIR "c:\\mysql\\data" 00387 #define PACKAGE "mysql" 00388 #define DEFAULT_BASEDIR "C:\\" 00389 #define SHAREDIR "share" 00390 #define DEFAULT_CHARSET_HOME "C:/mysql/" 00391 #endif 00392 #ifndef DEFAULT_HOME_ENV 00393 #define DEFAULT_HOME_ENV MYSQL_HOME 00394 #endif 00395 #ifndef DEFAULT_GROUP_SUFFIX_ENV 00396 #define DEFAULT_GROUP_SUFFIX_ENV MYSQL_GROUP_SUFFIX 00397 #endif 00398 00399 /* File name handling */ 00400 00401 #define FN_LIBCHAR '\\' 00402 #define FN_ROOTDIR "\\" 00403 #define FN_DEVCHAR ':' 00404 #define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */ 00405 #define FN_NO_CASE_SENCE /* Files are not case-sensitive */ 00406 #define OS_FILE_LIMIT 2048 00407 00408 #define DO_NOT_REMOVE_THREAD_WRAPPERS 00409 #define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V)) 00410 #define thread_safe_decrement(V,L) InterlockedDecrement((long*) &(V)) 00411 /* The following is only used for statistics, so it should be good enough */ 00412 #ifdef __NT__ /* This should also work on Win98 but .. */ 00413 #define thread_safe_add(V,C,L) InterlockedExchangeAdd((long*) &(V),(C)) 00414 #define thread_safe_sub(V,C,L) InterlockedExchangeAdd((long*) &(V),-(long) (C)) 00415 #define statistic_add(V,C,L) thread_safe_add((V),(C),(L)) 00416 #else 00417 #define thread_safe_add(V,C,L) \ 00418 pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L)); 00419 #define thread_safe_sub(V,C,L) \ 00420 pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L)); 00421 #define statistic_add(V,C,L) (V)+=(C) 00422 #endif 00423 #define statistic_increment(V,L) thread_safe_increment((V),(L)) 00424 #define statistic_decrement(V,L) thread_safe_decrement((V),(L)) 00425 00426 #define shared_memory_buffer_length 16000 00427 #define default_shared_memory_base_name "MYSQL" 00428 00429 #ifdef CYBOZU 00430 #define MYSQL_DEFAULT_CHARSET_NAME "utf8" 00431 #define MYSQL_DEFAULT_COLLATION_NAME "utf8_general_cs" 00432 #define HAVE_UTF8_GENERAL_CS 1 00433 #else 00434 #define MYSQL_DEFAULT_CHARSET_NAME "latin1" 00435 #define MYSQL_DEFAULT_COLLATION_NAME "latin1_swedish_ci" 00436 #endif 00437 00438 #define HAVE_SPATIAL 1 00439 #define HAVE_RTREE_KEYS 1 00440 #define HAVE_ROW_BASED_REPLICATION 1 00441 00442 #define HAVE_OPENSSL 1 00443 #define HAVE_YASSL 1 00444 00445 /* Define charsets you want */ 00446 /* #undef HAVE_CHARSET_armscii8 */ 00447 /* #undef HAVE_CHARSET_ascii */ 00448 #ifndef CYBOZU 00449 #define HAVE_CHARSET_big5 1 00450 #define HAVE_CHARSET_cp1250 1 00451 #endif 00452 /* #undef HAVE_CHARSET_cp1251 */ 00453 /* #undef HAVE_CHARSET_cp1256 */ 00454 /* #undef HAVE_CHARSET_cp1257 */ 00455 /* #undef HAVE_CHARSET_cp850 */ 00456 /* #undef HAVE_CHARSET_cp852 */ 00457 /* #undef HAVE_CHARSET_cp866 */ 00458 #define HAVE_CHARSET_cp932 1 00459 /* #undef HAVE_CHARSET_dec8 */ 00460 #ifndef CYBOZU 00461 #define HAVE_CHARSET_eucjpms 1 00462 #define HAVE_CHARSET_euckr 1 00463 #define HAVE_CHARSET_gb2312 1 00464 #define HAVE_CHARSET_gbk 1 00465 #endif 00466 /* #undef HAVE_CHARSET_greek */ 00467 /* #undef HAVE_CHARSET_hebrew */ 00468 /* #undef HAVE_CHARSET_hp8 */ 00469 /* #undef HAVE_CHARSET_keybcs2 */ 00470 /* #undef HAVE_CHARSET_koi8r */ 00471 /* #undef HAVE_CHARSET_koi8u */ 00472 #ifndef CYBOZU 00473 #define HAVE_CHARSET_latin1 1 00474 #define HAVE_CHARSET_latin2 1 00475 #endif 00476 /* #undef HAVE_CHARSET_latin5 */ 00477 /* #undef HAVE_CHARSET_latin7 */ 00478 /* #undef HAVE_CHARSET_macce */ 00479 /* #undef HAVE_CHARSET_macroman */ 00480 #define HAVE_CHARSET_sjis 1 00481 /* #undef HAVE_CHARSET_swe7 */ 00482 #ifndef CYBOZU 00483 #define HAVE_CHARSET_tis620 1 00484 #define HAVE_CHARSET_ucs2 1 00485 #define HAVE_CHARSET_ujis 1 00486 #endif 00487 #define HAVE_CHARSET_utf8 1 00488 #define HAVE_UCA_COLLATIONS 1 00489
1.4.7

