Debian Codegraph @

win/tclWinPort.h

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