diff options
Diffstat (limited to 'tcl/win/tclWinPort.h')
-rw-r--r-- | tcl/win/tclWinPort.h | 437 |
1 files changed, 233 insertions, 204 deletions
diff --git a/tcl/win/tclWinPort.h b/tcl/win/tclWinPort.h index 3dad58381cc..1ea45fe6b9a 100644 --- a/tcl/win/tclWinPort.h +++ b/tcl/win/tclWinPort.h @@ -5,7 +5,7 @@ * differences between Windows and Unix. It should be the only * file that contains #ifdefs to handle different flavors of OS. * - * Copyright (c) 1994-1996 Sun Microsystems, Inc. + * 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. @@ -16,30 +16,61 @@ #ifndef _TCLWINPORT #define _TCLWINPORT -#include <malloc.h> -#include <stdio.h> +#ifndef _TCLINT +# include "tclInt.h" +#endif + +#ifdef CHECK_UNICODE_CALLS + +#define _UNICODE +#define UNICODE + +#define __TCHAR_DEFINED +typedef float *_TCHAR; + +#define _TCHAR_DEFINED +typedef float *TCHAR; + +#endif + +/* + *--------------------------------------------------------------------------- + * The following sets of #includes and #ifdefs are required to get Tcl to + * compile under the windows compilers. + *--------------------------------------------------------------------------- + */ +#include <stdio.h> #include <stdlib.h> -#include <string.h> + #include <errno.h> +#include <fcntl.h> +#include <float.h> +#include <io.h> +#include <malloc.h> #include <process.h> #include <signal.h> -#include <winsock.h> +#include <string.h> + +/* + * Need to block out these includes for building extensions with MetroWerks + * compiler for Win32. + */ + +#ifndef __MWERKS__ #include <sys/stat.h> #include <sys/timeb.h> +#include <sys/utime.h> +#endif + #include <time.h> -#include <io.h> -#include <fcntl.h> -#include <float.h> + +#include <winsock2.h> #define WIN32_LEAN_AND_MEAN #include <windows.h> #undef WIN32_LEAN_AND_MEAN -#ifdef _MSC_VER -#define PASCAL -#endif - #ifdef BUILD_tcl # undef TCL_STORAGE_CLASS # define TCL_STORAGE_CLASS DLLEXPORT @@ -62,37 +93,112 @@ #endif /* - * The following defines wrap the system memory allocation routines for - * use by tclAlloc.c. + * The following defines redefine the Windows Socket errors as + * BSD errors so Tcl_PosixError can do the right thing. */ -/* On cygwin32, we just use the supplied malloc and free, rather than - using tclAlloc.c. The cygwin32 malloc is derived from the same - sources as tclAlloc.c, anyhow. */ -#ifdef __CYGWIN32__ -#define TclpAlloc(size) malloc(size) -#define TclpFree(ptr) free(ptr) -#define TclpRealloc(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)) +#ifndef EWOULDBLOCK +#define EWOULDBLOCK EAGAIN +#endif +#ifndef EALREADY +#define EALREADY 149 /* operation already in progress */ +#endif +#ifndef ENOTSOCK +#define ENOTSOCK 95 /* Socket operation on non-socket */ +#endif +#ifndef EDESTADDRREQ +#define EDESTADDRREQ 96 /* Destination address required */ +#endif +#ifndef EMSGSIZE +#define EMSGSIZE 97 /* Message too long */ +#endif +#ifndef EPROTOTYPE +#define EPROTOTYPE 98 /* Protocol wrong type for socket */ +#endif +#ifndef ENOPROTOOPT +#define ENOPROTOOPT 99 /* Protocol not available */ +#endif +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT 120 /* Protocol not supported */ +#endif +#ifndef ESOCKTNOSUPPORT +#define ESOCKTNOSUPPORT 121 /* Socket type not supported */ +#endif +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 122 /* Operation not supported on socket */ +#endif +#ifndef EPFNOSUPPORT +#define EPFNOSUPPORT 123 /* Protocol family not supported */ +#endif +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT 124 /* Address family not supported */ +#endif +#ifndef EADDRINUSE +#define EADDRINUSE 125 /* Address already in use */ +#endif +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL 126 /* Can't assign requested address */ +#endif +#ifndef ENETDOWN +#define ENETDOWN 127 /* Network is down */ +#endif +#ifndef ENETUNREACH +#define ENETUNREACH 128 /* Network is unreachable */ +#endif +#ifndef ENETRESET +#define ENETRESET 129 /* Network dropped connection on reset */ +#endif +#ifndef ECONNABORTED +#define ECONNABORTED 130 /* Software caused connection abort */ +#endif +#ifndef ECONNRESET +#define ECONNRESET 131 /* Connection reset by peer */ +#endif +#ifndef ENOBUFS +#define ENOBUFS 132 /* No buffer space available */ +#endif +#ifndef EISCONN +#define EISCONN 133 /* Socket is already connected */ +#endif +#ifndef ENOTCONN +#define ENOTCONN 134 /* Socket is not connected */ +#endif +#ifndef ESHUTDOWN +#define ESHUTDOWN 143 /* Can't send after socket shutdown */ +#endif +#ifndef ETOOMANYREFS +#define ETOOMANYREFS 144 /* Too many references: can't splice */ +#endif +#ifndef ETIMEDOUT +#define ETIMEDOUT 145 /* Connection timed out */ +#endif +#ifndef ECONNREFUSED +#define ECONNREFUSED 146 /* Connection refused */ +#endif +#ifndef ELOOP +#define ELOOP 90 /* Symbolic link loop */ +#endif +#ifndef EHOSTDOWN +#define EHOSTDOWN 147 /* Host is down */ +#endif +#ifndef EHOSTUNREACH +#define EHOSTUNREACH 148 /* No route to host */ +#endif +#ifndef ENOTEMPTY +#define ENOTEMPTY 93 /* directory not empty */ +#endif +#ifndef EUSERS +#define EUSERS 94 /* Too many users (for UFS) */ +#endif +#ifndef EDQUOT +#define EDQUOT 49 /* Disc quota exceeded */ +#endif +#ifndef ESTALE +#define ESTALE 151 /* Stale NFS file handle */ +#endif +#ifndef EREMOTE +#define EREMOTE 66 /* The object is remote */ #endif - -/* - * 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" /* * Supply definitions for macros to query wait status, if not already @@ -142,17 +248,9 @@ #endif /* - * Define MAXPATHLEN in terms of MAXPATH if available + * Define access mode constants if they aren't already defined. */ -#ifndef MAXPATH -#define MAXPATH MAX_PATH -#endif /* MAXPATH */ - -#ifndef MAXPATHLEN -#define MAXPATHLEN MAXPATH -#endif /* MAXPATHLEN */ - #ifndef F_OK # define F_OK 00 #endif @@ -208,6 +306,18 @@ # endif /* + * 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. */ @@ -219,145 +329,49 @@ #endif /* - * Provide a stub definition for TclGetUserHome(). - */ - -#define TclGetUserHome(name,bufferPtr) (NULL) - -/* * 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(). */ -#ifdef _MSC_VER +#if defined(_MSC_VER) || defined(__MINGW32__) # define environ _environ # define hypot _hypot # define exception _exception # undef EDEADLOCK -#endif /* _MSC_VER */ +# if defined(__MINGW32__) && !defined(__MSVCRT__) +# define timezone _timezone +# endif +#endif /* _MSC_VER || __MINGW32__ */ + +#ifdef __CYGWIN__ +/* On cygwin32, the environment is imported from the cygwin32 DLL. */ +__declspec(dllimport) extern char **__cygwin_environ; +# define environ __cygwin_environ +# define putenv TclCygwinPutenv +# define timezone _timezone +extern int chdir (const char*); +#endif /* __CYGWIN__ */ /* - * When building DLLs using GCC on mingw32, we must import environ via - * indirection. This hack will eventually go away once GCC understands - * dllimport attribute and mingw32 headers are fixed. + *--------------------------------------------------------------------------- + * 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. + *--------------------------------------------------------------------------- */ -#ifdef __MINGW32__ - extern char *** __imp__environ_dll; -# define environ (*__imp__environ_dll) -# define hypot _hypot -# define exception _exception -# undef EDEADLOCK -#endif /* __MINGW32__ */ +/* + * The default platform eol translation on Windows is TCL_TRANSLATE_CRLF: + */ + +#define TCL_PLATFORM_TRANSLATION TCL_TRANSLATE_CRLF /* - * The following defines redefine the Windows Socket errors as - * BSD errors so Tcl_PosixError can do the right thing. + * Declare dynamic loading extension macro. */ -#ifndef EWOULDBLOCK -#define EWOULDBLOCK EAGAIN -#endif -#ifndef EALREADY -#define EALREADY 149 /* operation already in progress */ -#endif -#ifndef ENOTSOCK -#define ENOTSOCK 95 /* Socket operation on non-socket */ -#endif -#ifndef EDESTADDRREQ -#define EDESTADDRREQ 96 /* Destination address required */ -#endif -#ifndef EMSGSIZE -#define EMSGSIZE 97 /* Message too long */ -#endif -#ifndef EPROTOTYPE -#define EPROTOTYPE 98 /* Protocol wrong type for socket */ -#endif -#ifndef ENOPROTOOPT -#define ENOPROTOOPT 99 /* Protocol not available */ -#endif -#ifndef EPROTONOSUPPORT -#define EPROTONOSUPPORT 120 /* Protocol not supported */ -#endif -#ifndef ESOCKTNOSUPPORT -#define ESOCKTNOSUPPORT 121 /* Socket type not supported */ -#endif -#ifndef EOPNOTSUPP -#define EOPNOTSUPP 122 /* Operation not supported on socket */ -#endif -#ifndef EPFNOSUPPORT -#define EPFNOSUPPORT 123 /* Protocol family not supported */ -#endif -#ifndef EAFNOSUPPORT -#define EAFNOSUPPORT 124 /* Address family not supported */ -#endif -#ifndef EADDRINUSE -#define EADDRINUSE 125 /* Address already in use */ -#endif -#ifndef EADDRNOTAVAIL -#define EADDRNOTAVAIL 126 /* Can't assign requested address */ -#endif -#ifndef ENETDOWN -#define ENETDOWN 127 /* Network is down */ -#endif -#ifndef ENETUNREACH -#define ENETUNREACH 128 /* Network is unreachable */ -#endif -#ifndef ENETRESET -#define ENETRESET 129 /* Network dropped connection on reset */ -#endif -#ifndef ECONNABORTED -#define ECONNABORTED 130 /* Software caused connection abort */ -#endif -#ifndef ECONNRESET -#define ECONNRESET 131 /* Connection reset by peer */ -#endif -#ifndef ENOBUFS -#define ENOBUFS 132 /* No buffer space available */ -#endif -#ifndef EISCONN -#define EISCONN 133 /* Socket is already connected */ -#endif -#ifndef ENOTCONN -#define ENOTCONN 134 /* Socket is not connected */ -#endif -#ifndef ESHUTDOWN -#define ESHUTDOWN 143 /* Can't send after socket shutdown */ -#endif -#ifndef ETOOMANYREFS -#define ETOOMANYREFS 144 /* Too many references: can't splice */ -#endif -#ifndef ETIMEDOUT -#define ETIMEDOUT 145 /* Connection timed out */ -#endif -#ifndef ECONNREFUSED -#define ECONNREFUSED 146 /* Connection refused */ -#endif -#ifndef ELOOP -#define ELOOP 90 /* Symbolic link loop */ -#endif -#ifndef EHOSTDOWN -#define EHOSTDOWN 147 /* Host is down */ -#endif -#ifndef EHOSTUNREACH -#define EHOSTUNREACH 148 /* No route to host */ -#endif -#ifndef ENOTEMPTY -#define ENOTEMPTY 93 /* directory not empty */ -#endif -#ifndef EUSERS -#define EUSERS 94 /* Too many users (for UFS) */ -#endif -#ifndef EDQUOT -#define EDQUOT 49 /* Disc quota exceeded */ -#endif -#ifndef ESTALE -#define ESTALE 151 /* Stale NFS file handle */ -#endif -#ifndef EREMOTE -#define EREMOTE 66 /* The object is remote */ -#endif +#define TCL_SHLIB_EXT ".dll" /* * The following define ensures that we use the native putenv @@ -366,7 +380,19 @@ */ #define USE_PUTENV 1 - + +/* + * The following defines wrap the system memory allocation routines for + * use by tclAlloc.c. + */ + +#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)) + /* * The following defines map from standard socket names to our internal * wrappers that redirect through the winSock function table (see the @@ -379,56 +405,59 @@ #define setsockopt TclWinSetSockOpt /* - * The following implements the Windows method for exiting the process. + * The following macros have trivial definitions, allowing generic code to + * address platform-specific issues. */ -#define TclPlatformExit(status) exit(status) +#define TclpReleaseFile(file) ckfree((char *) file) /* - * The following declarations belong in tclInt.h, but depend on platform - * specific types (e.g. struct tm). + * The following macros and declarations wrap the C runtime library + * functions. */ -EXTERN struct tm * TclpGetDate _ANSI_ARGS_((const time_t *tp, - int useGMT)); -EXTERN unsigned long TclpGetPid _ANSI_ARGS_((Tcl_Pid pid)); -EXTERN size_t TclStrftime _ANSI_ARGS_((char *s, size_t maxsize, - const char *format, const struct tm *t)); +#define TclpExit exit +#define TclpLstat TclpStat /* - * The following prototypes and defines replace the Windows versions - * of POSIX function that various compilier vendors didn't implement - * well or consistantly. + * Declarations for Windows-only functions. */ -#define lstat TclStat +EXTERN Tcl_Channel TclWinOpenSerialChannel _ANSI_ARGS_((HANDLE handle, + char *channelName, int permissions)); + +EXTERN Tcl_Channel TclWinOpenConsoleChannel _ANSI_ARGS_((HANDLE handle, + char *channelName, int permissions)); -EXTERN int TclpStat _ANSI_ARGS_((CONST char *path, - struct stat *buf)); -EXTERN int TclpAccess _ANSI_ARGS_((CONST char *path, - int mode)); +EXTERN Tcl_Channel TclWinOpenFileChannel _ANSI_ARGS_((HANDLE handle, + char *channelName, int permissions, int appendMode)); -#define TclpReleaseFile(file) ckfree((char *) file) +EXTERN TclFile TclWinMakeFile _ANSI_ARGS_((HANDLE handle)); /* - * Declarations for Windows specific functions. + * Platform specific mutex definition used by memory allocators. + * These mutexes are statically allocated and explicitly initialized. + * Most modules do not use this, but instead use Tcl_Mutex types and + * Tcl_MutexLock and Tcl_MutexUnlock that are self-initializing. */ -EXTERN void TclWinConvertError _ANSI_ARGS_((DWORD errCode)); -EXTERN void TclWinConvertWSAError _ANSI_ARGS_((DWORD errCode)); -EXTERN struct servent * PASCAL FAR - TclWinGetServByName _ANSI_ARGS_((const char FAR *nm, - const char FAR *proto)); -EXTERN int PASCAL FAR TclWinGetSockOpt _ANSI_ARGS_((SOCKET s, int level, - int optname, char FAR * optval, int FAR *optlen)); -EXTERN HINSTANCE TclWinGetTclInstance _ANSI_ARGS_((void)); -EXTERN HINSTANCE TclWinLoadLibrary _ANSI_ARGS_((char *name)); -EXTERN u_short PASCAL FAR - TclWinNToHS _ANSI_ARGS_((u_short ns)); -EXTERN int PASCAL FAR TclWinSetSockOpt _ANSI_ARGS_((SOCKET s, int level, - int optname, const char FAR * optval, int optlen)); +#ifdef TCL_THREADS +typedef CRITICAL_SECTION TclpMutex; +EXTERN void TclpMutexInit _ANSI_ARGS_((TclpMutex *mPtr)); +EXTERN void TclpMutexLock _ANSI_ARGS_((TclpMutex *mPtr)); +EXTERN void TclpMutexUnlock _ANSI_ARGS_((TclpMutex *mPtr)); +#else +typedef int TclpMutex; +#define TclpMutexInit(a) +#define TclpMutexLock(a) +#define TclpMutexUnlock(a) +#endif /* TCL_THREADS */ + +#include "tclPlatDecls.h" +#include "tclIntPlatDecls.h" # undef TCL_STORAGE_CLASS # define TCL_STORAGE_CLASS DLLIMPORT #endif /* _TCLWINPORT */ + |