Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

306 lines
9.2 KiB

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2. This library is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU Library General Public
  4. License as published by the Free Software Foundation; either
  5. version 2 of the License, or (at your option) any later version.
  6. This library is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  9. Library General Public License for more details.
  10. You should have received a copy of the GNU Library General Public
  11. License along with this library; if not, write to the Free
  12. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  13. MA 02111-1307, USA */
  14. /* Defines for Win32 to make it compatible for MySQL */
  15. #include <sys/locking.h>
  16. #include <windows.h>
  17. #include <math.h> /* Because of rint() */
  18. #include <fcntl.h>
  19. #include <io.h>
  20. #include <malloc.h>
  21. #if defined(__NT__)
  22. #define SYSTEM_TYPE "NT"
  23. #elif defined(__WIN2000__)
  24. #define SYSTEM_TYPE "WIN2000"
  25. #else
  26. #define SYSTEM_TYPE "Win95/Win98"
  27. #endif
  28. #ifdef _WIN64
  29. #define MACHINE_TYPE "ia64" /* Define to machine type name */
  30. #else
  31. #define MACHINE_TYPE "i32" /* Define to machine type name */
  32. #ifndef _WIN32
  33. #define _WIN32 /* Compatible with old source */
  34. #endif
  35. #ifndef __WIN32__
  36. #define __WIN32__
  37. #endif
  38. #endif /* _WIN64 */
  39. #ifndef __WIN__
  40. #define __WIN__ /* To make it easier in VC++ */
  41. #endif
  42. /* File and lock constants */
  43. #define O_SHARE 0x1000 /* Open file in sharing mode */
  44. #ifdef __BORLANDC__
  45. #define F_RDLCK LK_NBLCK /* read lock */
  46. #define F_WRLCK LK_NBRLCK /* write lock */
  47. #define F_UNLCK LK_UNLCK /* remove lock(s) */
  48. #else
  49. #define F_RDLCK _LK_NBLCK /* read lock */
  50. #define F_WRLCK _LK_NBRLCK /* write lock */
  51. #define F_UNLCK _LK_UNLCK /* remove lock(s) */
  52. #endif
  53. #define F_EXCLUSIVE 1 /* We have only exclusive locking */
  54. #define F_TO_EOF (INT_MAX32/2) /* size for lock of all file */
  55. #define F_OK 0 /* parameter to access() */
  56. #define S_IROTH S_IREAD /* for my_lib */
  57. #ifdef __BORLANDC__
  58. #define FILE_BINARY O_BINARY /* my_fopen in binary mode */
  59. #define O_TEMPORARY 0
  60. #define O_SHORT_LIVED 0
  61. #define SH_DENYNO _SH_DENYNO
  62. #else
  63. #define O_BINARY _O_BINARY /* compability with MSDOS */
  64. #define FILE_BINARY _O_BINARY /* my_fopen in binary mode */
  65. #define O_TEMPORARY _O_TEMPORARY
  66. #define O_SHORT_LIVED _O_SHORT_LIVED
  67. #define SH_DENYNO _SH_DENYNO
  68. #endif
  69. #define NO_OPEN_3 /* For my_create() */
  70. #define SIGQUIT SIGTERM /* No SIGQUIT */
  71. #undef _REENTRANT /* Crashes something for win32 */
  72. #undef SAFE_MUTEX /* Can't be used on windows */
  73. #define LONGLONG_MIN ((__int64) 0x8000000000000000)
  74. #define LONGLONG_MAX ((__int64) 0x7FFFFFFFFFFFFFFF)
  75. #define LL(A) ((__int64) A)
  76. /* Type information */
  77. typedef unsigned short ushort;
  78. typedef unsigned int uint;
  79. typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
  80. typedef __int64 longlong;
  81. typedef int sigset_t;
  82. #define longlong_defined
  83. /* off_t should not be __int64 because of conflicts in header files;
  84. Use my_off_t or os_off_t instead */
  85. typedef long off_t;
  86. typedef __int64 os_off_t;
  87. #ifdef _WIN64
  88. typedef UINT_PTR rf_SetTimer;
  89. #else
  90. typedef unsigned int size_t;
  91. typedef uint rf_SetTimer;
  92. #endif
  93. #define Socket_defined
  94. #define my_socket SOCKET
  95. #define bool BOOL
  96. #define SIGPIPE SIGINT
  97. #define RETQSORTTYPE void
  98. #define QSORT_TYPE_IS_VOID
  99. #define RETSIGTYPE void
  100. #define SOCKET_SIZE_TYPE int
  101. #define my_socket_defined
  102. #define bool_defined
  103. #define byte_defined
  104. #define HUGE_PTR
  105. #define STDCALL __stdcall /* Used by libmysql.dll */
  106. #ifndef UNDEF_THREAD_HACK
  107. #define THREAD
  108. #endif
  109. #define VOID_SIGHANDLER
  110. #define SIZEOF_CHAR 1
  111. #define SIZEOF_LONG 4
  112. #define SIZEOF_LONG_LONG 8
  113. #define SIZEOF_OFF_T 8
  114. #define HAVE_BROKEN_NETINET_INCLUDES
  115. #ifdef __NT__
  116. #define HAVE_NAMED_PIPE /* We can only create pipes on NT */
  117. #endif
  118. /* Use all character sets in MySQL */
  119. #define USE_MB 1
  120. #define USE_MB_IDENT 1
  121. #define USE_STRCOLL 1
  122. /* Convert some simple functions to Posix */
  123. #define sigset(A,B) signal((A),(B))
  124. #define finite(A) _finite(A)
  125. #define sleep(A) Sleep((A)*1000)
  126. #ifndef __BORLANDC__
  127. #define access(A,B) _access(A,B)
  128. #endif
  129. #if defined(__cplusplus)
  130. inline double rint(double nr)
  131. {
  132. double f = floor(nr);
  133. double c = ceil(nr);
  134. return (((c-nr) >= (nr-f)) ? f :c);
  135. }
  136. #ifdef _WIN64
  137. #define ulonglong2double(A) ((double) (A))
  138. #define my_off_t2double(A) ((double) (A))
  139. #else
  140. inline double ulonglong2double(ulonglong value)
  141. {
  142. longlong nr=(longlong) value;
  143. if (nr >= 0)
  144. return (double) nr;
  145. return (18446744073709551616.0 + (double) nr);
  146. }
  147. #define my_off_t2double(A) ulonglong2double(A)
  148. #endif /* _WIN64 */
  149. #else
  150. #define inline __inline
  151. #endif /* __cplusplus */
  152. #if SIZEOF_OFF_T > 4
  153. #define lseek(A,B,C) _lseeki64((A),(longlong) (B),(C))
  154. #define tell(A) _telli64(A)
  155. #endif
  156. #define STACK_DIRECTION -1
  157. /* Optimized store functions for Intel x86 */
  158. #define sint2korr(A) (*((int16 *) (A)))
  159. #define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
  160. (((uint32) 255L << 24) | \
  161. (((uint32) (uchar) (A)[2]) << 16) |\
  162. (((uint32) (uchar) (A)[1]) << 8) | \
  163. ((uint32) (uchar) (A)[0])) : \
  164. (((uint32) (uchar) (A)[2]) << 16) |\
  165. (((uint32) (uchar) (A)[1]) << 8) | \
  166. ((uint32) (uchar) (A)[0])))
  167. #define sint4korr(A) (*((long *) (A)))
  168. #define uint2korr(A) (*((uint16 *) (A)))
  169. #define uint3korr(A) (long) (*((unsigned long *) (A)) & 0xFFFFFF)
  170. #define uint4korr(A) (*((unsigned long *) (A)))
  171. #define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
  172. (((uint32) ((uchar) (A)[1])) << 8) +\
  173. (((uint32) ((uchar) (A)[2])) << 16) +\
  174. (((uint32) ((uchar) (A)[3])) << 24)) +\
  175. (((ulonglong) ((uchar) (A)[4])) << 32))
  176. #define uint8korr(A) (*((ulonglong *) (A)))
  177. #define sint8korr(A) (*((longlong *) (A)))
  178. #define int2store(T,A) *((uint16*) (T))= (uint16) (A)
  179. #define int3store(T,A) { *(T)= (uchar) ((A));\
  180. *(T+1)=(uchar) (((uint) (A) >> 8));\
  181. *(T+2)=(uchar) (((A) >> 16)); }
  182. #define int4store(T,A) *((long *) (T))= (long) (A)
  183. #define int5store(T,A) { *(T)= (uchar)((A));\
  184. *((T)+1)=(uchar) (((A) >> 8));\
  185. *((T)+2)=(uchar) (((A) >> 16));\
  186. *((T)+3)=(uchar) (((A) >> 24)); \
  187. *((T)+4)=(uchar) (((A) >> 32)); }
  188. #define int8store(T,A) *((ulonglong *) (T))= (ulonglong) (A)
  189. #define doubleget(V,M) { *((long *) &V) = *((long*) M); \
  190. *(((long *) &V)+1) = *(((long*) M)+1); }
  191. #define doublestore(T,V) { *((long *) T) = *((long*) &V); \
  192. *(((long *) T)+1) = *(((long*) &V)+1); }
  193. #define float4get(V,M) { *((long *) &(V)) = *((long*) (M)); }
  194. #define float8get(V,M) doubleget((V),(M))
  195. #define float4store(V,M) memcpy((byte*) V,(byte*) (&M),sizeof(float))
  196. #define float8store(V,M) doublestore((V),(M))
  197. #define HAVE_PERROR
  198. #define HAVE_VFPRINT
  199. #define HAVE_CHSIZE /* System has chsize() function */
  200. #define HAVE_RENAME /* Have rename() as function */
  201. #define HAVE_BINARY_STREAMS /* Have "b" flag in streams */
  202. #define HAVE_LONG_JMP /* Have long jump function */
  203. #define HAVE_LOCKING /* have locking() call */
  204. #define HAVE_ERRNO_AS_DEFINE /* errno is a define */
  205. #define HAVE_STDLIB /* everything is include in this file */
  206. #define HAVE_MEMCPY
  207. #define HAVE_MEMMOVE
  208. #define HAVE_GETCWD
  209. #define HAVE_TELL
  210. #define HAVE_TZNAME
  211. #define HAVE_PUTENV
  212. #define HAVE_SELECT
  213. #define HAVE_SETLOCALE
  214. #define HAVE_SOCKET /* Giangi */
  215. #define HAVE_FLOAT_H
  216. #define HAVE_LIMITS_H
  217. #define HAVE_STDDEF_H
  218. #define HAVE_RINT /* defined in this file */
  219. #define NO_FCNTL_NONBLOCK /* No FCNTL */
  220. #define HAVE_ALLOCA
  221. #define HAVE_STRPBRK
  222. #define HAVE_STRSTR
  223. #define HAVE_COMPRESS
  224. #ifdef NOT_USED
  225. #define HAVE_SNPRINTF /* Gave link error */
  226. #define _snprintf snprintf
  227. #endif
  228. #ifdef _MSC_VER
  229. #define HAVE_LDIV /* The optimizer breaks in zortech for ldiv */
  230. #define HAVE_ANSI_INCLUDE
  231. #define HAVE_SYS_UTIME_H
  232. #define HAVE_STRTOUL
  233. #endif
  234. #define my_reinterpret_cast(A) reinterpret_cast <A>
  235. #define my_const_cast(A) const_cast<A>
  236. /* MYSQL OPTIONS */
  237. #ifdef _CUSTOMCONFIG_
  238. #include <custom_conf.h>
  239. #else
  240. #define DEFAULT_MYSQL_HOME "c:\\mysql"
  241. #define PACKAGE "mysql"
  242. #define DEFAULT_BASEDIR "C:\\"
  243. #define SHAREDIR "share"
  244. #define DEFAULT_CHARSET_HOME "C:/mysql/"
  245. #endif
  246. /* File name handling */
  247. #define FN_LIBCHAR '\\'
  248. #define FN_ROOTDIR "\\"
  249. #define FN_NETWORK_DRIVES /* Uses \\ to indicate network drives */
  250. #define FN_NO_CASE_SENCE /* Files are not case-sensitive */
  251. #define MY_NFILE 1024
  252. #define DO_NOT_REMOVE_THREAD_WRAPPERS
  253. #define thread_safe_increment(V,L) InterlockedIncrement((long*) &(V))
  254. /* The following is only used for statistics, so it should be good enough */
  255. #ifdef __NT__ /* This should also work on Win98 but .. */
  256. #define thread_safe_add(V,C,L) InterlockedExchangeAdd((long*) &(V),(C))
  257. #define thread_safe_sub(V,C,L) InterlockedExchangeAdd((long*) &(V),-(long) (C))
  258. #define statistic_add(V,C,L) thread_safe_add((V),(C),(L))
  259. #else
  260. #define thread_safe_add(V,C,L) \
  261. pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L));
  262. #define thread_safe_sub(V,C,L) \
  263. pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L));
  264. #define statistic_add(V,C,L) (V)+=(C)
  265. #endif
  266. #define statistic_increment(V,L) thread_safe_increment((V),(L))