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 * RCS: @(#) $Id: tclWinPort.h,v 1.50.2.3 2010/05/25 10:37:18 nijtmans Exp $ 14 */ 15 16#ifndef _TCLWINPORT 17#define _TCLWINPORT 18 19#define WIN32_LEAN_AND_MEAN 20#include <windows.h> 21#undef WIN32_LEAN_AND_MEAN 22 23/* 24 * Ask for the winsock function typedefs, also. 25 */ 26#define INCL_WINSOCK_API_TYPEDEFS 1 27#include <winsock2.h> 28 29#ifdef CHECK_UNICODE_CALLS 30# define _UNICODE 31# define UNICODE 32# define __TCHAR_DEFINED 33 typedef float *_TCHAR; 34# define _TCHAR_DEFINED 35 typedef float *TCHAR; 36#endif /* CHECK_UNICODE_CALLS */ 37 38/* 39 *--------------------------------------------------------------------------- 40 * The following sets of #includes and #ifdefs are required to get Tcl to 41 * compile under the windows compilers. 42 *--------------------------------------------------------------------------- 43 */ 44 45#ifdef __CYGWIN__ 46# include <unistd.h> 47# include <wchar.h> 48#else 49# include <io.h> 50#endif 51#include <stdio.h> 52#include <stdlib.h> 53#include <errno.h> 54#include <fcntl.h> 55#include <float.h> 56#include <malloc.h> 57#include <process.h> 58#include <signal.h> 59#include <string.h> 60#include <limits.h> 61 62#ifdef __CYGWIN__ 63# include <unistd.h> 64# ifndef _wcsicmp 65# define _wcsicmp wcscasecmp 66# endif 67#else 68# ifndef strncasecmp 69# define strncasecmp strnicmp 70# endif 71# ifndef strcasecmp 72# define strcasecmp stricmp 73# endif 74#endif 75 76/* 77 * Need to block out these includes for building extensions with MetroWerks 78 * compiler for Win32. 79 */ 80 81#ifndef __MWERKS__ 82#include <sys/stat.h> 83#include <sys/timeb.h> 84# ifdef __BORLANDC__ 85# include <utime.h> 86# else 87# include <sys/utime.h> 88# endif /* __BORLANDC__ */ 89#endif /* __MWERKS__ */ 90 91#include <time.h> 92 93/* 94 * Define EINPROGRESS in terms of WSAEINPROGRESS. 95 */ 96 97#ifndef EINPROGRESS 98# define EINPROGRESS WSAEINPROGRESS 99#endif 100 101/* 102 * If ENOTSUP is not defined, define it to a value that will never occur. 103 */ 104 105#ifndef ENOTSUP 106# define ENOTSUP -1030507 107#endif 108 109/* 110 * The following defines redefine the Windows Socket errors as 111 * BSD errors so Tcl_PosixError can do the right thing. 112 */ 113 114#ifndef EWOULDBLOCK 115# define EWOULDBLOCK EAGAIN 116#endif 117#ifndef EALREADY 118# define EALREADY 149 /* operation already in progress */ 119#endif 120#ifndef ENOTSOCK 121# define ENOTSOCK 95 /* Socket operation on non-socket */ 122#endif 123#ifndef EDESTADDRREQ 124# define EDESTADDRREQ 96 /* Destination address required */ 125#endif 126#ifndef EMSGSIZE 127# define EMSGSIZE 97 /* Message too long */ 128#endif 129#ifndef EPROTOTYPE 130# define EPROTOTYPE 98 /* Protocol wrong type for socket */ 131#endif 132#ifndef ENOPROTOOPT 133# define ENOPROTOOPT 99 /* Protocol not available */ 134#endif 135#ifndef EPROTONOSUPPORT 136# define EPROTONOSUPPORT 120 /* Protocol not supported */ 137#endif 138#ifndef ESOCKTNOSUPPORT 139# define ESOCKTNOSUPPORT 121 /* Socket type not supported */ 140#endif 141#ifndef EOPNOTSUPP 142# define EOPNOTSUPP 122 /* Operation not supported on socket */ 143#endif 144#ifndef EPFNOSUPPORT 145# define EPFNOSUPPORT 123 /* Protocol family not supported */ 146#endif 147#ifndef EAFNOSUPPORT 148# define EAFNOSUPPORT 124 /* Address family not supported */ 149#endif 150#ifndef EADDRINUSE 151# define EADDRINUSE 125 /* Address already in use */ 152#endif 153#ifndef EADDRNOTAVAIL 154# define EADDRNOTAVAIL 126 /* Can't assign requested address */ 155#endif 156#ifndef ENETDOWN 157# define ENETDOWN 127 /* Network is down */ 158#endif 159#ifndef ENETUNREACH 160# define ENETUNREACH 128 /* Network is unreachable */ 161#endif 162#ifndef ENETRESET 163# define ENETRESET 129 /* Network dropped connection on reset */ 164#endif 165#ifndef ECONNABORTED 166# define ECONNABORTED 130 /* Software caused connection abort */ 167#endif 168#ifndef ECONNRESET 169# define ECONNRESET 131 /* Connection reset by peer */ 170#endif 171#ifndef ENOBUFS 172# define ENOBUFS 132 /* No buffer space available */ 173#endif 174#ifndef EISCONN 175# define EISCONN 133 /* Socket is already connected */ 176#endif 177#ifndef ENOTCONN 178# define ENOTCONN 134 /* Socket is not connected */ 179#endif 180#ifndef ESHUTDOWN 181# define ESHUTDOWN 143 /* Can't send after socket shutdown */ 182#endif 183#ifndef ETOOMANYREFS 184# define ETOOMANYREFS 144 /* Too many references: can't splice */ 185#endif 186#ifndef ETIMEDOUT 187# define ETIMEDOUT 145 /* Connection timed out */ 188#endif 189#ifndef ECONNREFUSED 190# define ECONNREFUSED 146 /* Connection refused */ 191#endif 192#ifndef ELOOP 193# define ELOOP 90 /* Symbolic link loop */ 194#endif 195#ifndef EHOSTDOWN 196# define EHOSTDOWN 147 /* Host is down */ 197#endif 198#ifndef EHOSTUNREACH 199# define EHOSTUNREACH 148 /* No route to host */ 200#endif 201#ifndef ENOTEMPTY 202# define ENOTEMPTY 93 /* directory not empty */ 203#endif 204#ifndef EUSERS 205# define EUSERS 94 /* Too many users (for UFS) */ 206#endif 207#ifndef EDQUOT 208# define EDQUOT 69 /* Disc quota exceeded */ 209#endif 210#ifndef ESTALE 211# define ESTALE 151 /* Stale NFS file handle */ 212#endif 213#ifndef EREMOTE 214# define EREMOTE 66 /* The object is remote */ 215#endif 216 217/* 218 * It is very hard to determine how Windows reacts to attempting to 219 * set a file pointer outside the input datatype's representable 220 * region. So we fake the error code ourselves. 221 */ 222 223#ifndef EOVERFLOW 224# ifdef EFBIG 225# define EOVERFLOW EFBIG /* The object couldn't fit in the datatype */ 226# else /* !EFBIG */ 227# define EOVERFLOW EINVAL /* Better than nothing! */ 228# endif /* EFBIG */ 229#endif /* !EOVERFLOW */ 230 231/* 232 * Signals not known to the standard ANSI signal.h. These are used 233 * by Tcl_WaitPid() and generic/tclPosixStr.c 234 */ 235 236#ifndef SIGTRAP 237# define SIGTRAP 5 238#endif 239#ifndef SIGBUS 240# define SIGBUS 10 241#endif 242 243/* 244 * Supply definitions for macros to query wait status, if not already 245 * defined in header files above. 246 */ 247 248#if TCL_UNION_WAIT 249# define WAIT_STATUS_TYPE union wait 250#else 251# define WAIT_STATUS_TYPE int 252#endif /* TCL_UNION_WAIT */ 253 254#ifndef WIFEXITED 255# define WIFEXITED(stat) (((*((int *) &(stat))) & 0xC0000000) == 0) 256#endif 257 258#ifndef WEXITSTATUS 259# define WEXITSTATUS(stat) (*((int *) &(stat))) 260#endif 261 262#ifndef WIFSIGNALED 263# define WIFSIGNALED(stat) ((*((int *) &(stat))) & 0xC0000000) 264#endif 265 266#ifndef WTERMSIG 267# define WTERMSIG(stat) ((*((int *) &(stat))) & 0x7f) 268#endif 269 270#ifndef WIFSTOPPED 271# define WIFSTOPPED(stat) 0 272#endif 273 274#ifndef WSTOPSIG 275# define WSTOPSIG(stat) (((*((int *) &(stat))) >> 8) & 0xff) 276#endif 277 278/* 279 * Define constants for waitpid() system call if they aren't defined 280 * by a system header file. 281 */ 282 283#ifndef WNOHANG 284# define WNOHANG 1 285#endif 286#ifndef WUNTRACED 287# define WUNTRACED 2 288#endif 289 290/* 291 * Define access mode constants if they aren't already defined. 292 */ 293 294#ifndef F_OK 295# define F_OK 00 296#endif 297#ifndef X_OK 298# define X_OK 01 299#endif 300#ifndef W_OK 301# define W_OK 02 302#endif 303#ifndef R_OK 304# define R_OK 04 305#endif 306 307/* 308 * Define macros to query file type bits, if they're not already 309 * defined. 310 */ 311 312#ifndef S_IFLNK 313# define S_IFLNK 0120000 /* Symbolic Link */ 314#endif 315 316#ifndef S_ISREG 317# ifdef S_IFREG 318# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 319# else 320# define S_ISREG(m) 0 321# endif 322#endif /* !S_ISREG */ 323#ifndef S_ISDIR 324# ifdef S_IFDIR 325# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 326# else 327# define S_ISDIR(m) 0 328# endif 329#endif /* !S_ISDIR */ 330#ifndef S_ISCHR 331# ifdef S_IFCHR 332# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 333# else 334# define S_ISCHR(m) 0 335# endif 336#endif /* !S_ISCHR */ 337#ifndef S_ISBLK 338# ifdef S_IFBLK 339# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 340# else 341# define S_ISBLK(m) 0 342# endif 343#endif /* !S_ISBLK */ 344#ifndef S_ISFIFO 345# ifdef S_IFIFO 346# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 347# else 348# define S_ISFIFO(m) 0 349# endif 350#endif /* !S_ISFIFO */ 351#ifndef S_ISLNK 352# ifdef S_IFLNK 353# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) 354# else 355# define S_ISLNK(m) 0 356# endif 357#endif /* !S_ISLNK */ 358 359 360/* 361 * Define MAXPATHLEN in terms of MAXPATH if available 362 */ 363 364#ifndef MAXPATH 365# define MAXPATH MAX_PATH 366#endif /* MAXPATH */ 367 368#ifndef MAXPATHLEN 369# define MAXPATHLEN MAXPATH 370#endif /* MAXPATHLEN */ 371 372/* 373 * Define pid_t and uid_t if they're not already defined. 374 */ 375 376#if ! TCL_PID_T 377# define pid_t int 378#endif /* !TCL_PID_T */ 379#if ! TCL_UID_T 380# define uid_t int 381#endif /* !TCL_UID_T */ 382 383/* 384 * Visual C++ has some odd names for common functions, so we need to 385 * define a few macros to handle them. Also, it defines EDEADLOCK and 386 * EDEADLK as the same value, which confuses Tcl_ErrnoId(). 387 */ 388 389#if defined(_MSC_VER) || defined(__MINGW32__) 390# define environ _environ 391# define hypot _hypot 392# define exception _exception 393# undef EDEADLOCK 394# if defined(__MINGW32__) && !defined(__MSVCRT__) 395# define timezone _timezone 396# endif 397#endif /* _MSC_VER || __MINGW32__ */ 398 399/* 400 * Borland's timezone and environ functions. 401 */ 402 403#ifdef __BORLANDC__ 404# define timezone _timezone 405# define environ _environ 406#endif /* __BORLANDC__ */ 407 408#ifdef __WATCOMC__ 409 /* 410 * OpenWatcom uses a wine derived winsock2.h that is missing the 411 * LPFN_* typedefs. 412 */ 413# define HAVE_NO_LPFN_DECLS 414# if !defined(__CHAR_SIGNED__) 415# error "You must use the -j switch to ensure char is signed." 416# endif 417#endif 418 419 420/* 421 * MSVC 8.0 started to mark many standard C library functions depreciated 422 * including the *printf family and others. Tell it to shut up. 423 * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0) 424 */ 425#if _MSC_VER >= 1400 426#pragma warning(disable:4996) 427#endif 428 429 430/* 431 * There is no platform-specific panic routine for Windows in the Tcl internals. 432 */ 433 434#define TclpPanic ((Tcl_PanicProc *) NULL) 435 436/* 437 *--------------------------------------------------------------------------- 438 * The following macros and declarations represent the interface between 439 * generic and windows-specific parts of Tcl. Some of the macros may 440 * override functions declared in tclInt.h. 441 *--------------------------------------------------------------------------- 442 */ 443 444/* 445 * The default platform eol translation on Windows is TCL_TRANSLATE_CRLF: 446 */ 447 448#define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF 449 450/* 451 * Declare dynamic loading extension macro. 452 */ 453 454#define TCL_SHLIB_EXT ".dll" 455 456/* 457 * The following define ensures that we use the native putenv 458 * implementation to modify the environment array. This keeps 459 * the C level environment in synch with the system level environment. 460 */ 461 462#define USE_PUTENV 1 463#define USE_PUTENV_FOR_UNSET 1 464 465/* 466 * Msvcrt's putenv() copies the string rather than takes ownership of it. 467 */ 468 469#if defined(_MSC_VER) || defined(__MINGW32__) 470# define HAVE_PUTENV_THAT_COPIES 1 471#endif 472 473/* 474 * Older version of Mingw are known to lack a MWMO_ALERTABLE define. 475 */ 476#if defined(HAVE_NO_MWMO_ALERTABLE) 477# define MWMO_ALERTABLE 2 478#endif 479 480/* 481 * The following defines wrap the system memory allocation routines for 482 * use by tclAlloc.c. 483 */ 484 485#ifdef __CYGWIN__ 486# define TclpSysAlloc(size, isBin) malloc((size)) 487# define TclpSysFree(ptr) free((ptr)) 488# define TclpSysRealloc(ptr, size) realloc((ptr), (size)) 489#else 490# define TclpSysAlloc(size, isBin) ((void*)HeapAlloc(GetProcessHeap(), \ 491 (DWORD)0, (DWORD)size)) 492# define TclpSysFree(ptr) (HeapFree(GetProcessHeap(), \ 493 (DWORD)0, (HGLOBAL)ptr)) 494# define TclpSysRealloc(ptr, size) ((void*)HeapReAlloc(GetProcessHeap(), \ 495 (DWORD)0, (LPVOID)ptr, (DWORD)size)) 496#endif 497 498/* 499 * The following defines map from standard socket names to our internal 500 * wrappers that redirect through the winSock function table (see the 501 * file tclWinSock.c). 502 */ 503 504#define getservbyname TclWinGetServByName 505#define getsockopt TclWinGetSockOpt 506#define ntohs TclWinNToHS 507#define setsockopt TclWinSetSockOpt 508/* This type is not defined in the Windows headers */ 509#define socklen_t int 510 511 512/* 513 * The following macros have trivial definitions, allowing generic code to 514 * address platform-specific issues. 515 */ 516 517#define TclpReleaseFile(file) ckfree((char *) file) 518 519/* 520 * The following macros and declarations wrap the C runtime library 521 * functions. 522 */ 523 524#define TclpExit exit 525 526#ifndef INVALID_SET_FILE_POINTER 527#define INVALID_SET_FILE_POINTER 0xFFFFFFFF 528#endif /* INVALID_SET_FILE_POINTER */ 529 530#endif /* _TCLWINPORT */ 531