tclWinPort.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /*
  2. * tclWinPort.h --
  3. *
  4. * This header file handles porting issues that occur because of
  5. * differences between Windows and Unix. It should be the only
  6. * file that contains #ifdefs to handle different flavors of OS.
  7. *
  8. * Copyright (c) 1994-1997 Sun Microsystems, Inc.
  9. *
  10. * See the file "license.terms" for information on usage and redistribution
  11. * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. */
  13. #ifndef _TCLWINPORT
  14. #define _TCLWINPORT
  15. #if !defined(_WIN64) && !defined(__MINGW_USE_VC2005_COMPAT)
  16. /* See [Bug 3354324]: file mtime sets wrong time */
  17. # define __MINGW_USE_VC2005_COMPAT
  18. #endif
  19. /*
  20. * We must specify the lower version we intend to support.
  21. *
  22. * WINVER = 0x0501 means Windows XP and above
  23. */
  24. #ifndef WINVER
  25. # define WINVER 0x0501
  26. #endif
  27. #ifndef _WIN32_WINNT
  28. # define _WIN32_WINNT 0x0501
  29. #endif
  30. #define WIN32_LEAN_AND_MEAN
  31. #include <windows.h>
  32. #undef WIN32_LEAN_AND_MEAN
  33. /* Compatibility to older visual studio / windows platform SDK */
  34. #if !defined(MAXULONG_PTR)
  35. typedef DWORD DWORD_PTR;
  36. typedef DWORD_PTR * PDWORD_PTR;
  37. #endif
  38. /*
  39. * Ask for the winsock function typedefs, also.
  40. */
  41. #ifndef INCL_WINSOCK_API_TYPEDEFS
  42. # define INCL_WINSOCK_API_TYPEDEFS 1
  43. #endif
  44. #include <winsock2.h>
  45. #include <ws2tcpip.h>
  46. #ifdef HAVE_WSPIAPI_H
  47. # include <wspiapi.h>
  48. #endif
  49. #ifdef CHECK_UNICODE_CALLS
  50. # define _UNICODE
  51. # define UNICODE
  52. # define __TCHAR_DEFINED
  53. typedef float *_TCHAR;
  54. # define _TCHAR_DEFINED
  55. typedef float *TCHAR;
  56. #endif /* CHECK_UNICODE_CALLS */
  57. /*
  58. * Pull in the typedef of TCHAR for windows.
  59. */
  60. #include <tchar.h>
  61. #ifndef _TCHAR_DEFINED
  62. /* Borland seems to forget to set this. */
  63. typedef _TCHAR TCHAR;
  64. # define _TCHAR_DEFINED
  65. #endif
  66. #if defined(_MSC_VER) && defined(__STDC__)
  67. /* VS2005 SP1 misses this. See [Bug #3110161] */
  68. typedef _TCHAR TCHAR;
  69. #endif
  70. /*
  71. *---------------------------------------------------------------------------
  72. * The following sets of #includes and #ifdefs are required to get Tcl to
  73. * compile under the windows compilers.
  74. *---------------------------------------------------------------------------
  75. */
  76. #include <time.h>
  77. #include <wchar.h>
  78. #include <io.h>
  79. #include <errno.h>
  80. #include <fcntl.h>
  81. #include <float.h>
  82. #include <malloc.h>
  83. #include <process.h>
  84. #include <signal.h>
  85. #ifdef HAVE_INTTYPES_H
  86. # include <inttypes.h>
  87. #endif
  88. #include <limits.h>
  89. #ifndef __GNUC__
  90. # define strncasecmp _strnicmp
  91. # define strcasecmp _stricmp
  92. #endif
  93. /*
  94. * Need to block out these includes for building extensions with MetroWerks
  95. * compiler for Win32.
  96. */
  97. #ifndef __MWERKS__
  98. #include <sys/stat.h>
  99. #include <sys/timeb.h>
  100. # ifdef __BORLANDC__
  101. # include <utime.h>
  102. # else
  103. # include <sys/utime.h>
  104. # endif /* __BORLANDC__ */
  105. #endif /* __MWERKS__ */
  106. /*
  107. * The following defines redefine the Windows Socket errors as
  108. * BSD errors so Tcl_PosixError can do the right thing.
  109. */
  110. #ifndef ENOTEMPTY
  111. # define ENOTEMPTY 41 /* Directory not empty */
  112. #endif
  113. #ifndef EREMOTE
  114. # define EREMOTE 66 /* The object is remote */
  115. #endif
  116. #ifndef EPFNOSUPPORT
  117. # define EPFNOSUPPORT 96 /* Protocol family not supported */
  118. #endif
  119. #ifndef EADDRINUSE
  120. # define EADDRINUSE 100 /* Address already in use */
  121. #endif
  122. #ifndef EADDRNOTAVAIL
  123. # define EADDRNOTAVAIL 101 /* Can't assign requested address */
  124. #endif
  125. #ifndef EAFNOSUPPORT
  126. # define EAFNOSUPPORT 102 /* Address family not supported */
  127. #endif
  128. #ifndef EALREADY
  129. # define EALREADY 103 /* Operation already in progress */
  130. #endif
  131. #ifndef EBADMSG
  132. # define EBADMSG 104 /* Not a data message */
  133. #endif
  134. #ifndef ECANCELED
  135. # define ECANCELED 105 /* Canceled */
  136. #endif
  137. #ifndef ECONNABORTED
  138. # define ECONNABORTED 106 /* Software caused connection abort */
  139. #endif
  140. #ifndef ECONNREFUSED
  141. # define ECONNREFUSED 107 /* Connection refused */
  142. #endif
  143. #ifndef ECONNRESET
  144. # define ECONNRESET 108 /* Connection reset by peer */
  145. #endif
  146. #ifndef EDESTADDRREQ
  147. # define EDESTADDRREQ 109 /* Destination address required */
  148. #endif
  149. #ifndef EHOSTUNREACH
  150. # define EHOSTUNREACH 110 /* No route to host */
  151. #endif
  152. #ifndef EIDRM
  153. # define EIDRM 111 /* Identifier removed */
  154. #endif
  155. #ifndef EINPROGRESS
  156. # define EINPROGRESS 112 /* Operation now in progress */
  157. #endif
  158. #ifndef EISCONN
  159. # define EISCONN 113 /* Socket is already connected */
  160. #endif
  161. #ifndef ELOOP
  162. # define ELOOP 114 /* Symbolic link loop */
  163. #endif
  164. #ifndef EMSGSIZE
  165. # define EMSGSIZE 115 /* Message too long */
  166. #endif
  167. #ifndef ENETDOWN
  168. # define ENETDOWN 116 /* Network is down */
  169. #endif
  170. #ifndef ENETRESET
  171. # define ENETRESET 117 /* Network dropped connection on reset */
  172. #endif
  173. #ifndef ENETUNREACH
  174. # define ENETUNREACH 118 /* Network is unreachable */
  175. #endif
  176. #ifndef ENOBUFS
  177. # define ENOBUFS 119 /* No buffer space available */
  178. #endif
  179. #ifndef ENODATA
  180. # define ENODATA 120 /* No data available */
  181. #endif
  182. #ifndef ENOLINK
  183. # define ENOLINK 121 /* Link has be severed */
  184. #endif
  185. #ifndef ENOMSG
  186. # define ENOMSG 122 /* No message of desired type */
  187. #endif
  188. #ifndef ENOPROTOOPT
  189. # define ENOPROTOOPT 123 /* Protocol not available */
  190. #endif
  191. #ifndef ENOSR
  192. # define ENOSR 124 /* Out of stream resources */
  193. #endif
  194. #ifndef ENOSTR
  195. # define ENOSTR 125 /* Not a stream device */
  196. #endif
  197. #ifndef ENOTCONN
  198. # define ENOTCONN 126 /* Socket is not connected */
  199. #endif
  200. #ifndef ENOTRECOVERABLE
  201. # define ENOTRECOVERABLE 127 /* Not recoverable */
  202. #endif
  203. #ifndef ENOTSOCK
  204. # define ENOTSOCK 128 /* Socket operation on non-socket */
  205. #endif
  206. #ifndef ENOTSUP
  207. # define ENOTSUP 129 /* Operation not supported */
  208. #endif
  209. #ifndef EOPNOTSUPP
  210. # define EOPNOTSUPP 130 /* Operation not supported on socket */
  211. #endif
  212. #ifndef EOTHER
  213. # define EOTHER 131 /* Other error */
  214. #endif
  215. #ifndef EOVERFLOW
  216. # define EOVERFLOW 132 /* File too big */
  217. #endif
  218. #ifndef EOWNERDEAD
  219. # define EOWNERDEAD 133 /* Owner dead */
  220. #endif
  221. #ifndef EPROTO
  222. # define EPROTO 134 /* Protocol error */
  223. #endif
  224. #ifndef EPROTONOSUPPORT
  225. # define EPROTONOSUPPORT 135 /* Protocol not supported */
  226. #endif
  227. #ifndef EPROTOTYPE
  228. # define EPROTOTYPE 136 /* Protocol wrong type for socket */
  229. #endif
  230. #ifndef ETIME
  231. # define ETIME 137 /* Timer expired */
  232. #endif
  233. #ifndef ETIMEDOUT
  234. # define ETIMEDOUT 138 /* Connection timed out */
  235. #endif
  236. #ifndef ETXTBSY
  237. # define ETXTBSY 139 /* Text file or pseudo-device busy */
  238. #endif
  239. #ifndef EWOULDBLOCK
  240. # define EWOULDBLOCK 140 /* Operation would block */
  241. #endif
  242. /* Visual Studio doesn't have these, so just choose some high numbers */
  243. #ifndef ESOCKTNOSUPPORT
  244. # define ESOCKTNOSUPPORT 240 /* Socket type not supported */
  245. #endif
  246. #ifndef ESHUTDOWN
  247. # define ESHUTDOWN 241 /* Can't send after socket shutdown */
  248. #endif
  249. #ifndef ETOOMANYREFS
  250. # define ETOOMANYREFS 242 /* Too many references: can't splice */
  251. #endif
  252. #ifndef EHOSTDOWN
  253. # define EHOSTDOWN 243 /* Host is down */
  254. #endif
  255. #ifndef EUSERS
  256. # define EUSERS 244 /* Too many users (for UFS) */
  257. #endif
  258. #ifndef EDQUOT
  259. # define EDQUOT 245 /* Disc quota exceeded */
  260. #endif
  261. #ifndef ESTALE
  262. # define ESTALE 246 /* Stale NFS file handle */
  263. #endif
  264. /*
  265. * Signals not known to the standard ANSI signal.h. These are used
  266. * by Tcl_WaitPid() and generic/tclPosixStr.c
  267. */
  268. #ifndef SIGTRAP
  269. # define SIGTRAP 5
  270. #endif
  271. #ifndef SIGBUS
  272. # define SIGBUS 10
  273. #endif
  274. /*
  275. * Supply definitions for macros to query wait status, if not already
  276. * defined in header files above.
  277. */
  278. #ifdef TCL_UNION_WAIT
  279. # define WAIT_STATUS_TYPE union wait
  280. #else
  281. # define WAIT_STATUS_TYPE int
  282. #endif /* TCL_UNION_WAIT */
  283. #ifndef WIFEXITED
  284. # define WIFEXITED(stat) (((*((int *) &(stat))) & 0xC0000000) == 0)
  285. #endif
  286. #ifndef WEXITSTATUS
  287. # define WEXITSTATUS(stat) (*((int *) &(stat)))
  288. #endif
  289. #ifndef WIFSIGNALED
  290. # define WIFSIGNALED(stat) ((*((int *) &(stat))) & 0xC0000000)
  291. #endif
  292. #ifndef WTERMSIG
  293. # define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7F)
  294. #endif
  295. #ifndef WIFSTOPPED
  296. # define WIFSTOPPED(stat) 0
  297. #endif
  298. #ifndef WSTOPSIG
  299. # define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xFF)
  300. #endif
  301. /*
  302. * Define constants for waitpid() system call if they aren't defined
  303. * by a system header file.
  304. */
  305. #ifndef WNOHANG
  306. # define WNOHANG 1
  307. #endif
  308. #ifndef WUNTRACED
  309. # define WUNTRACED 2
  310. #endif
  311. /*
  312. * Define access mode constants if they aren't already defined.
  313. */
  314. #ifndef F_OK
  315. # define F_OK 00
  316. #endif
  317. #ifndef X_OK
  318. # define X_OK 01
  319. #endif
  320. #ifndef W_OK
  321. # define W_OK 02
  322. #endif
  323. #ifndef R_OK
  324. # define R_OK 04
  325. #endif
  326. /*
  327. * Define macros to query file type bits, if they're not already
  328. * defined.
  329. */
  330. #ifndef S_IFLNK
  331. # define S_IFLNK 0120000 /* Symbolic Link */
  332. #endif
  333. /*
  334. * Windows compilers do not define S_IFBLK. However, Tcl uses it in
  335. * GetTypeFromMode to identify blockSpecial devices based on the
  336. * value in the statsbuf st_mode field. We have no other way to pass this
  337. * from NativeStat on Windows so are forced to define it here.
  338. * The definition here is essentially what is seen on Linux and MingW.
  339. * XXX - the root problem is Tcl using Unix definitions instead of
  340. * abstracting the structure into a platform independent one. Sigh - perhaps
  341. * Tcl 9
  342. */
  343. #ifndef S_IFBLK
  344. # define S_IFBLK (S_IFDIR | S_IFCHR)
  345. #endif
  346. #ifndef S_ISREG
  347. # ifdef S_IFREG
  348. # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  349. # else
  350. # define S_ISREG(m) 0
  351. # endif
  352. #endif /* !S_ISREG */
  353. #ifndef S_ISDIR
  354. # ifdef S_IFDIR
  355. # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  356. # else
  357. # define S_ISDIR(m) 0
  358. # endif
  359. #endif /* !S_ISDIR */
  360. #ifndef S_ISCHR
  361. # ifdef S_IFCHR
  362. # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  363. # else
  364. # define S_ISCHR(m) 0
  365. # endif
  366. #endif /* !S_ISCHR */
  367. #ifndef S_ISBLK
  368. # ifdef S_IFBLK
  369. # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  370. # else
  371. # define S_ISBLK(m) 0
  372. # endif
  373. #endif /* !S_ISBLK */
  374. #ifndef S_ISFIFO
  375. # ifdef S_IFIFO
  376. # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  377. # else
  378. # define S_ISFIFO(m) 0
  379. # endif
  380. #endif /* !S_ISFIFO */
  381. #ifndef S_ISLNK
  382. # ifdef S_IFLNK
  383. # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  384. # else
  385. # define S_ISLNK(m) 0
  386. # endif
  387. #endif /* !S_ISLNK */
  388. /*
  389. * Define MAXPATHLEN in terms of MAXPATH if available
  390. */
  391. #ifndef MAXPATH
  392. # define MAXPATH MAX_PATH
  393. #endif /* MAXPATH */
  394. #ifndef MAXPATHLEN
  395. # define MAXPATHLEN MAXPATH
  396. #endif /* MAXPATHLEN */
  397. /*
  398. * Define pid_t and uid_t if they're not already defined.
  399. */
  400. #if !defined(TCL_PID_T)
  401. # define pid_t int
  402. #endif /* !TCL_PID_T */
  403. #if !defined(TCL_UID_T)
  404. # define uid_t int
  405. #endif /* !TCL_UID_T */
  406. /*
  407. * Visual C++ has some odd names for common functions, so we need to
  408. * define a few macros to handle them. Also, it defines EDEADLOCK and
  409. * EDEADLK as the same value, which confuses Tcl_ErrnoId().
  410. */
  411. #if defined(_MSC_VER) || defined(__MSVCRT__)
  412. # define environ _environ
  413. # if defined(_MSC_VER) && (_MSC_VER < 1600)
  414. # define hypot _hypot
  415. # endif
  416. # define exception _exception
  417. # undef EDEADLOCK
  418. # if defined(_MSC_VER) && (_MSC_VER >= 1700)
  419. # define timezone _timezone
  420. # endif
  421. #endif /* _MSC_VER || __MSVCRT__ */
  422. /*
  423. * Borland's timezone and environ functions.
  424. */
  425. #ifdef __BORLANDC__
  426. # define timezone _timezone
  427. # define environ _environ
  428. #endif /* __BORLANDC__ */
  429. #ifdef __WATCOMC__
  430. # if !defined(__CHAR_SIGNED__)
  431. # error "You must use the -j switch to ensure char is signed."
  432. # endif
  433. #endif
  434. /*
  435. * MSVC 8.0 started to mark many standard C library functions depreciated
  436. * including the *printf family and others. Tell it to shut up.
  437. * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0)
  438. */
  439. #if defined(_MSC_VER)
  440. # pragma warning(disable:4146)
  441. # pragma warning(disable:4244)
  442. # if _MSC_VER >= 1400
  443. # pragma warning(disable:4267)
  444. # pragma warning(disable:4996)
  445. # endif
  446. #endif
  447. /*
  448. *---------------------------------------------------------------------------
  449. * The following macros and declarations represent the interface between
  450. * generic and windows-specific parts of Tcl. Some of the macros may
  451. * override functions declared in tclInt.h.
  452. *---------------------------------------------------------------------------
  453. */
  454. /*
  455. * The default platform eol translation on Windows is TCL_TRANSLATE_CRLF:
  456. */
  457. #define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF
  458. /*
  459. * Declare dynamic loading extension macro.
  460. */
  461. #define TCL_SHLIB_EXT ".dll"
  462. /*
  463. * The following define ensures that we use the native putenv
  464. * implementation to modify the environment array. This keeps
  465. * the C level environment in synch with the system level environment.
  466. */
  467. #define USE_PUTENV 1
  468. #define USE_PUTENV_FOR_UNSET 1
  469. /*
  470. * Msvcrt's putenv() copies the string rather than takes ownership of it.
  471. */
  472. #if defined(_MSC_VER) || defined(__MSVCRT__)
  473. # define HAVE_PUTENV_THAT_COPIES 1
  474. #endif
  475. /*
  476. * Older version of Mingw are known to lack a MWMO_ALERTABLE define.
  477. */
  478. #if !defined(MWMO_ALERTABLE)
  479. # define MWMO_ALERTABLE 2
  480. #endif
  481. /*
  482. * The following defines wrap the system memory allocation routines for
  483. * use by tclAlloc.c.
  484. */
  485. #define TclpSysAlloc(size, isBin) ((void*)HeapAlloc(GetProcessHeap(), \
  486. (DWORD)0, (DWORD)size))
  487. #define TclpSysFree(ptr) (HeapFree(GetProcessHeap(), \
  488. (DWORD)0, (HGLOBAL)ptr))
  489. #define TclpSysRealloc(ptr, size) ((void*)HeapReAlloc(GetProcessHeap(), \
  490. (DWORD)0, (LPVOID)ptr, (DWORD)size))
  491. /* This type is not defined in the Windows headers */
  492. #define socklen_t int
  493. /*
  494. * The following macros have trivial definitions, allowing generic code to
  495. * address platform-specific issues.
  496. */
  497. #define TclpReleaseFile(file) ckfree((char *) file)
  498. /*
  499. * The following macros and declarations wrap the C runtime library
  500. * functions.
  501. */
  502. #define TclpExit exit
  503. #ifndef INVALID_SET_FILE_POINTER
  504. #define INVALID_SET_FILE_POINTER 0xFFFFFFFF
  505. #endif /* INVALID_SET_FILE_POINTER */
  506. #ifndef LABEL_SECURITY_INFORMATION
  507. # define LABEL_SECURITY_INFORMATION (0x00000010L)
  508. #endif
  509. #define Tcl_DirEntry void
  510. #define TclDIR void
  511. #endif /* _TCLWINPORT */