1 |
dashley |
71 |
/* $Header$ */ |
2 |
|
|
/* |
3 |
|
|
* tclWinPort.h -- |
4 |
|
|
* |
5 |
|
|
* This header file handles porting issues that occur because of |
6 |
|
|
* differences between Windows and Unix. It should be the only |
7 |
|
|
* file that contains #ifdefs to handle different flavors of OS. |
8 |
|
|
* |
9 |
|
|
* Copyright (c) 1994-1997 Sun Microsystems, Inc. |
10 |
|
|
* |
11 |
|
|
* See the file "license.terms" for information on usage and redistribution |
12 |
|
|
* of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
13 |
|
|
* |
14 |
|
|
* RCS: @(#) $Id: tclwinport.h,v 1.1.1.1 2001/06/13 04:49:51 dtashley Exp $ |
15 |
|
|
*/ |
16 |
|
|
|
17 |
|
|
#ifndef _TCLWINPORT |
18 |
|
|
#define _TCLWINPORT |
19 |
|
|
|
20 |
|
|
#ifndef _TCLINT |
21 |
|
|
# include "tclInt.h" |
22 |
|
|
#endif |
23 |
|
|
|
24 |
|
|
#ifdef CHECK_UNICODE_CALLS |
25 |
|
|
|
26 |
|
|
#define _UNICODE |
27 |
|
|
#define UNICODE |
28 |
|
|
|
29 |
|
|
#define __TCHAR_DEFINED |
30 |
|
|
typedef float *_TCHAR; |
31 |
|
|
|
32 |
|
|
#define _TCHAR_DEFINED |
33 |
|
|
typedef float *TCHAR; |
34 |
|
|
|
35 |
|
|
#endif |
36 |
|
|
|
37 |
|
|
/* |
38 |
|
|
*--------------------------------------------------------------------------- |
39 |
|
|
* The following sets of #includes and #ifdefs are required to get Tcl to |
40 |
|
|
* compile under the windows compilers. |
41 |
|
|
*--------------------------------------------------------------------------- |
42 |
|
|
*/ |
43 |
|
|
|
44 |
|
|
#include <stdio.h> |
45 |
|
|
#include <stdlib.h> |
46 |
|
|
|
47 |
|
|
#include <direct.h> |
48 |
|
|
#include <errno.h> |
49 |
|
|
#include <fcntl.h> |
50 |
|
|
#include <float.h> |
51 |
|
|
#include <io.h> |
52 |
|
|
#include <malloc.h> |
53 |
|
|
#include <process.h> |
54 |
|
|
#include <signal.h> |
55 |
|
|
#include <string.h> |
56 |
|
|
|
57 |
|
|
/* |
58 |
|
|
* Need to block out these includes for building extensions with MetroWerks |
59 |
|
|
* compiler for Win32. |
60 |
|
|
*/ |
61 |
|
|
|
62 |
|
|
#ifndef __MWERKS__ |
63 |
|
|
#include <sys/stat.h> |
64 |
|
|
#include <sys/timeb.h> |
65 |
|
|
#include <sys/utime.h> |
66 |
|
|
#endif |
67 |
|
|
|
68 |
|
|
#include <tchar.h> |
69 |
|
|
#include <time.h> |
70 |
|
|
#include <winsock2.h> |
71 |
|
|
|
72 |
|
|
#define WIN32_LEAN_AND_MEAN |
73 |
|
|
#include <windows.h> |
74 |
|
|
#undef WIN32_LEAN_AND_MEAN |
75 |
|
|
|
76 |
|
|
#ifdef BUILD_tcl |
77 |
|
|
# undef TCL_STORAGE_CLASS |
78 |
|
|
# define TCL_STORAGE_CLASS DLLEXPORT |
79 |
|
|
#endif |
80 |
|
|
|
81 |
|
|
/* |
82 |
|
|
* Define EINPROGRESS in terms of WSAEINPROGRESS. |
83 |
|
|
*/ |
84 |
|
|
|
85 |
|
|
#ifndef EINPROGRESS |
86 |
|
|
#define EINPROGRESS WSAEINPROGRESS |
87 |
|
|
#endif |
88 |
|
|
|
89 |
|
|
/* |
90 |
|
|
* If ENOTSUP is not defined, define it to a value that will never occur. |
91 |
|
|
*/ |
92 |
|
|
|
93 |
|
|
#ifndef ENOTSUP |
94 |
|
|
#define ENOTSUP -1030507 |
95 |
|
|
#endif |
96 |
|
|
|
97 |
|
|
/* |
98 |
|
|
* The following defines redefine the Windows Socket errors as |
99 |
|
|
* BSD errors so Tcl_PosixError can do the right thing. |
100 |
|
|
*/ |
101 |
|
|
|
102 |
|
|
#ifndef EWOULDBLOCK |
103 |
|
|
#define EWOULDBLOCK EAGAIN |
104 |
|
|
#endif |
105 |
|
|
#ifndef EALREADY |
106 |
|
|
#define EALREADY 149 /* operation already in progress */ |
107 |
|
|
#endif |
108 |
|
|
#ifndef ENOTSOCK |
109 |
|
|
#define ENOTSOCK 95 /* Socket operation on non-socket */ |
110 |
|
|
#endif |
111 |
|
|
#ifndef EDESTADDRREQ |
112 |
|
|
#define EDESTADDRREQ 96 /* Destination address required */ |
113 |
|
|
#endif |
114 |
|
|
#ifndef EMSGSIZE |
115 |
|
|
#define EMSGSIZE 97 /* Message too long */ |
116 |
|
|
#endif |
117 |
|
|
#ifndef EPROTOTYPE |
118 |
|
|
#define EPROTOTYPE 98 /* Protocol wrong type for socket */ |
119 |
|
|
#endif |
120 |
|
|
#ifndef ENOPROTOOPT |
121 |
|
|
#define ENOPROTOOPT 99 /* Protocol not available */ |
122 |
|
|
#endif |
123 |
|
|
#ifndef EPROTONOSUPPORT |
124 |
|
|
#define EPROTONOSUPPORT 120 /* Protocol not supported */ |
125 |
|
|
#endif |
126 |
|
|
#ifndef ESOCKTNOSUPPORT |
127 |
|
|
#define ESOCKTNOSUPPORT 121 /* Socket type not supported */ |
128 |
|
|
#endif |
129 |
|
|
#ifndef EOPNOTSUPP |
130 |
|
|
#define EOPNOTSUPP 122 /* Operation not supported on socket */ |
131 |
|
|
#endif |
132 |
|
|
#ifndef EPFNOSUPPORT |
133 |
|
|
#define EPFNOSUPPORT 123 /* Protocol family not supported */ |
134 |
|
|
#endif |
135 |
|
|
#ifndef EAFNOSUPPORT |
136 |
|
|
#define EAFNOSUPPORT 124 /* Address family not supported */ |
137 |
|
|
#endif |
138 |
|
|
#ifndef EADDRINUSE |
139 |
|
|
#define EADDRINUSE 125 /* Address already in use */ |
140 |
|
|
#endif |
141 |
|
|
#ifndef EADDRNOTAVAIL |
142 |
|
|
#define EADDRNOTAVAIL 126 /* Can't assign requested address */ |
143 |
|
|
#endif |
144 |
|
|
#ifndef ENETDOWN |
145 |
|
|
#define ENETDOWN 127 /* Network is down */ |
146 |
|
|
#endif |
147 |
|
|
#ifndef ENETUNREACH |
148 |
|
|
#define ENETUNREACH 128 /* Network is unreachable */ |
149 |
|
|
#endif |
150 |
|
|
#ifndef ENETRESET |
151 |
|
|
#define ENETRESET 129 /* Network dropped connection on reset */ |
152 |
|
|
#endif |
153 |
|
|
#ifndef ECONNABORTED |
154 |
|
|
#define ECONNABORTED 130 /* Software caused connection abort */ |
155 |
|
|
#endif |
156 |
|
|
#ifndef ECONNRESET |
157 |
|
|
#define ECONNRESET 131 /* Connection reset by peer */ |
158 |
|
|
#endif |
159 |
|
|
#ifndef ENOBUFS |
160 |
|
|
#define ENOBUFS 132 /* No buffer space available */ |
161 |
|
|
#endif |
162 |
|
|
#ifndef EISCONN |
163 |
|
|
#define EISCONN 133 /* Socket is already connected */ |
164 |
|
|
#endif |
165 |
|
|
#ifndef ENOTCONN |
166 |
|
|
#define ENOTCONN 134 /* Socket is not connected */ |
167 |
|
|
#endif |
168 |
|
|
#ifndef ESHUTDOWN |
169 |
|
|
#define ESHUTDOWN 143 /* Can't send after socket shutdown */ |
170 |
|
|
#endif |
171 |
|
|
#ifndef ETOOMANYREFS |
172 |
|
|
#define ETOOMANYREFS 144 /* Too many references: can't splice */ |
173 |
|
|
#endif |
174 |
|
|
#ifndef ETIMEDOUT |
175 |
|
|
#define ETIMEDOUT 145 /* Connection timed out */ |
176 |
|
|
#endif |
177 |
|
|
#ifndef ECONNREFUSED |
178 |
|
|
#define ECONNREFUSED 146 /* Connection refused */ |
179 |
|
|
#endif |
180 |
|
|
#ifndef ELOOP |
181 |
|
|
#define ELOOP 90 /* Symbolic link loop */ |
182 |
|
|
#endif |
183 |
|
|
#ifndef EHOSTDOWN |
184 |
|
|
#define EHOSTDOWN 147 /* Host is down */ |
185 |
|
|
#endif |
186 |
|
|
#ifndef EHOSTUNREACH |
187 |
|
|
#define EHOSTUNREACH 148 /* No route to host */ |
188 |
|
|
#endif |
189 |
|
|
#ifndef ENOTEMPTY |
190 |
|
|
#define ENOTEMPTY 93 /* directory not empty */ |
191 |
|
|
#endif |
192 |
|
|
#ifndef EUSERS |
193 |
|
|
#define EUSERS 94 /* Too many users (for UFS) */ |
194 |
|
|
#endif |
195 |
|
|
#ifndef EDQUOT |
196 |
|
|
#define EDQUOT 49 /* Disc quota exceeded */ |
197 |
|
|
#endif |
198 |
|
|
#ifndef ESTALE |
199 |
|
|
#define ESTALE 151 /* Stale NFS file handle */ |
200 |
|
|
#endif |
201 |
|
|
#ifndef EREMOTE |
202 |
|
|
#define EREMOTE 66 /* The object is remote */ |
203 |
|
|
#endif |
204 |
|
|
|
205 |
|
|
/* |
206 |
|
|
* Supply definitions for macros to query wait status, if not already |
207 |
|
|
* defined in header files above. |
208 |
|
|
*/ |
209 |
|
|
|
210 |
|
|
#if TCL_UNION_WAIT |
211 |
|
|
# define WAIT_STATUS_TYPE union wait |
212 |
|
|
#else |
213 |
|
|
# define WAIT_STATUS_TYPE int |
214 |
|
|
#endif |
215 |
|
|
|
216 |
|
|
#ifndef WIFEXITED |
217 |
|
|
# define WIFEXITED(stat) (((*((int *) &(stat))) & 0xff) == 0) |
218 |
|
|
#endif |
219 |
|
|
|
220 |
|
|
#ifndef WEXITSTATUS |
221 |
|
|
# define WEXITSTATUS(stat) (((*((int *) &(stat))) >> 8) & 0xff) |
222 |
|
|
#endif |
223 |
|
|
|
224 |
|
|
#ifndef WIFSIGNALED |
225 |
|
|
# define WIFSIGNALED(stat) (((*((int *) &(stat)))) && ((*((int *) &(stat))) == ((*((int *) &(stat))) & 0x00ff))) |
226 |
|
|
#endif |
227 |
|
|
|
228 |
|
|
#ifndef WTERMSIG |
229 |
|
|
# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f) |
230 |
|
|
#endif |
231 |
|
|
|
232 |
|
|
#ifndef WIFSTOPPED |
233 |
|
|
# define WIFSTOPPED(stat) (((*((int *) &(stat))) & 0xff) == 0177) |
234 |
|
|
#endif |
235 |
|
|
|
236 |
|
|
#ifndef WSTOPSIG |
237 |
|
|
# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff) |
238 |
|
|
#endif |
239 |
|
|
|
240 |
|
|
/* |
241 |
|
|
* Define constants for waitpid() system call if they aren't defined |
242 |
|
|
* by a system header file. |
243 |
|
|
*/ |
244 |
|
|
|
245 |
|
|
#ifndef WNOHANG |
246 |
|
|
# define WNOHANG 1 |
247 |
|
|
#endif |
248 |
|
|
#ifndef WUNTRACED |
249 |
|
|
# define WUNTRACED 2 |
250 |
|
|
#endif |
251 |
|
|
|
252 |
|
|
/* |
253 |
|
|
* Define access mode constants if they aren't already defined. |
254 |
|
|
*/ |
255 |
|
|
|
256 |
|
|
#ifndef F_OK |
257 |
|
|
# define F_OK 00 |
258 |
|
|
#endif |
259 |
|
|
#ifndef X_OK |
260 |
|
|
# define X_OK 01 |
261 |
|
|
#endif |
262 |
|
|
#ifndef W_OK |
263 |
|
|
# define W_OK 02 |
264 |
|
|
#endif |
265 |
|
|
#ifndef R_OK |
266 |
|
|
# define R_OK 04 |
267 |
|
|
#endif |
268 |
|
|
|
269 |
|
|
/* |
270 |
|
|
* Define macros to query file type bits, if they're not already |
271 |
|
|
* defined. |
272 |
|
|
*/ |
273 |
|
|
|
274 |
|
|
#ifndef S_ISREG |
275 |
|
|
# ifdef S_IFREG |
276 |
|
|
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) |
277 |
|
|
# else |
278 |
|
|
# define S_ISREG(m) 0 |
279 |
|
|
# endif |
280 |
|
|
# endif |
281 |
|
|
#ifndef S_ISDIR |
282 |
|
|
# ifdef S_IFDIR |
283 |
|
|
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) |
284 |
|
|
# else |
285 |
|
|
# define S_ISDIR(m) 0 |
286 |
|
|
# endif |
287 |
|
|
# endif |
288 |
|
|
#ifndef S_ISCHR |
289 |
|
|
# ifdef S_IFCHR |
290 |
|
|
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) |
291 |
|
|
# else |
292 |
|
|
# define S_ISCHR(m) 0 |
293 |
|
|
# endif |
294 |
|
|
# endif |
295 |
|
|
#ifndef S_ISBLK |
296 |
|
|
# ifdef S_IFBLK |
297 |
|
|
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) |
298 |
|
|
# else |
299 |
|
|
# define S_ISBLK(m) 0 |
300 |
|
|
# endif |
301 |
|
|
# endif |
302 |
|
|
#ifndef S_ISFIFO |
303 |
|
|
# ifdef S_IFIFO |
304 |
|
|
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) |
305 |
|
|
# else |
306 |
|
|
# define S_ISFIFO(m) 0 |
307 |
|
|
# endif |
308 |
|
|
# endif |
309 |
|
|
|
310 |
|
|
/* |
311 |
|
|
* Define MAXPATHLEN in terms of MAXPATH if available |
312 |
|
|
*/ |
313 |
|
|
|
314 |
|
|
#ifndef MAXPATH |
315 |
|
|
#define MAXPATH MAX_PATH |
316 |
|
|
#endif /* MAXPATH */ |
317 |
|
|
|
318 |
|
|
#ifndef MAXPATHLEN |
319 |
|
|
#define MAXPATHLEN MAXPATH |
320 |
|
|
#endif /* MAXPATHLEN */ |
321 |
|
|
|
322 |
|
|
/* |
323 |
|
|
* Define pid_t and uid_t if they're not already defined. |
324 |
|
|
*/ |
325 |
|
|
|
326 |
|
|
#if ! TCL_PID_T |
327 |
|
|
# define pid_t int |
328 |
|
|
#endif |
329 |
|
|
#if ! TCL_UID_T |
330 |
|
|
# define uid_t int |
331 |
|
|
#endif |
332 |
|
|
|
333 |
|
|
/* |
334 |
|
|
* Visual C++ has some odd names for common functions, so we need to |
335 |
|
|
* define a few macros to handle them. Also, it defines EDEADLOCK and |
336 |
|
|
* EDEADLK as the same value, which confuses Tcl_ErrnoId(). |
337 |
|
|
*/ |
338 |
|
|
|
339 |
|
|
#if defined(_MSC_VER) || defined(__MINGW32__) |
340 |
|
|
# define environ _environ |
341 |
|
|
# define hypot _hypot |
342 |
|
|
# define exception _exception |
343 |
|
|
# undef EDEADLOCK |
344 |
|
|
# if defined(__MINGW32__) && !defined(__MSVCRT__) |
345 |
|
|
# define timezone _timezone |
346 |
|
|
# endif |
347 |
|
|
#endif /* _MSC_VER || __MINGW32__ */ |
348 |
|
|
|
349 |
|
|
/* |
350 |
|
|
*--------------------------------------------------------------------------- |
351 |
|
|
* The following macros and declarations represent the interface between |
352 |
|
|
* generic and windows-specific parts of Tcl. Some of the macros may |
353 |
|
|
* override functions declared in tclInt.h. |
354 |
|
|
*--------------------------------------------------------------------------- |
355 |
|
|
*/ |
356 |
|
|
|
357 |
|
|
/* |
358 |
|
|
* The default platform eol translation on Windows is TCL_TRANSLATE_CRLF: |
359 |
|
|
*/ |
360 |
|
|
|
361 |
|
|
#define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF |
362 |
|
|
|
363 |
|
|
/* |
364 |
|
|
* Declare dynamic loading extension macro. |
365 |
|
|
*/ |
366 |
|
|
|
367 |
|
|
#define TCL_SHLIB_EXT ".dll" |
368 |
|
|
|
369 |
|
|
/* |
370 |
|
|
* The following define ensures that we use the native putenv |
371 |
|
|
* implementation to modify the environment array. This keeps |
372 |
|
|
* the C level environment in synch with the system level environment. |
373 |
|
|
*/ |
374 |
|
|
|
375 |
|
|
#define USE_PUTENV 1 |
376 |
|
|
|
377 |
|
|
/* |
378 |
|
|
* The following defines wrap the system memory allocation routines for |
379 |
|
|
* use by tclAlloc.c. |
380 |
|
|
*/ |
381 |
|
|
|
382 |
|
|
#define TclpSysAlloc(size, isBin) ((void*)HeapAlloc(GetProcessHeap(), \ |
383 |
|
|
(DWORD)0, (DWORD)size)) |
384 |
|
|
#define TclpSysFree(ptr) (HeapFree(GetProcessHeap(), \ |
385 |
|
|
(DWORD)0, (HGLOBAL)ptr)) |
386 |
|
|
#define TclpSysRealloc(ptr, size) ((void*)HeapReAlloc(GetProcessHeap(), \ |
387 |
|
|
(DWORD)0, (LPVOID)ptr, (DWORD)size)) |
388 |
|
|
|
389 |
|
|
/* |
390 |
|
|
* The following defines map from standard socket names to our internal |
391 |
|
|
* wrappers that redirect through the winSock function table (see the |
392 |
|
|
* file tclWinSock.c). |
393 |
|
|
*/ |
394 |
|
|
|
395 |
|
|
#define getservbyname TclWinGetServByName |
396 |
|
|
#define getsockopt TclWinGetSockOpt |
397 |
|
|
#define ntohs TclWinNToHS |
398 |
|
|
#define setsockopt TclWinSetSockOpt |
399 |
|
|
|
400 |
|
|
/* |
401 |
|
|
* The following macros have trivial definitions, allowing generic code to |
402 |
|
|
* address platform-specific issues. |
403 |
|
|
*/ |
404 |
|
|
|
405 |
|
|
#define TclpReleaseFile(file) ckfree((char *) file) |
406 |
|
|
|
407 |
|
|
/* |
408 |
|
|
* The following macros and declarations wrap the C runtime library |
409 |
|
|
* functions. |
410 |
|
|
*/ |
411 |
|
|
|
412 |
|
|
#define TclpExit exit |
413 |
|
|
#define TclpLstat TclpStat |
414 |
|
|
|
415 |
|
|
/* |
416 |
|
|
* Declarations for Windows-only functions. |
417 |
|
|
*/ |
418 |
|
|
|
419 |
|
|
EXTERN Tcl_Channel TclWinOpenSerialChannel _ANSI_ARGS_((HANDLE handle, |
420 |
|
|
char *channelName, int permissions)); |
421 |
|
|
|
422 |
|
|
EXTERN Tcl_Channel TclWinOpenConsoleChannel _ANSI_ARGS_((HANDLE handle, |
423 |
|
|
char *channelName, int permissions)); |
424 |
|
|
|
425 |
|
|
EXTERN Tcl_Channel TclWinOpenFileChannel _ANSI_ARGS_((HANDLE handle, |
426 |
|
|
char *channelName, int permissions, int appendMode)); |
427 |
|
|
|
428 |
|
|
EXTERN TclFile TclWinMakeFile _ANSI_ARGS_((HANDLE handle)); |
429 |
|
|
|
430 |
|
|
/* |
431 |
|
|
* Platform specific mutex definition used by memory allocators. |
432 |
|
|
* These mutexes are statically allocated and explicitly initialized. |
433 |
|
|
* Most modules do not use this, but instead use Tcl_Mutex types and |
434 |
|
|
* Tcl_MutexLock and Tcl_MutexUnlock that are self-initializing. |
435 |
|
|
*/ |
436 |
|
|
|
437 |
|
|
#ifdef TCL_THREADS |
438 |
|
|
typedef CRITICAL_SECTION TclpMutex; |
439 |
|
|
EXTERN void TclpMutexInit _ANSI_ARGS_((TclpMutex *mPtr)); |
440 |
|
|
EXTERN void TclpMutexLock _ANSI_ARGS_((TclpMutex *mPtr)); |
441 |
|
|
EXTERN void TclpMutexUnlock _ANSI_ARGS_((TclpMutex *mPtr)); |
442 |
|
|
#else |
443 |
|
|
typedef int TclpMutex; |
444 |
|
|
#define TclpMutexInit(a) |
445 |
|
|
#define TclpMutexLock(a) |
446 |
|
|
#define TclpMutexUnlock(a) |
447 |
|
|
#endif /* TCL_THREADS */ |
448 |
|
|
|
449 |
|
|
#include "tclPlatDecls.h" |
450 |
|
|
#include "tclIntPlatDecls.h" |
451 |
|
|
|
452 |
|
|
# undef TCL_STORAGE_CLASS |
453 |
|
|
# define TCL_STORAGE_CLASS DLLIMPORT |
454 |
|
|
|
455 |
|
|
#endif /* _TCLWINPORT */ |
456 |
|
|
|
457 |
|
|
/* End of tclwinport.h */ |