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