diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-04-02 09:45:33 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-04-02 09:45:33 (GMT) |
commit | 968face14f7b3c39dab97d0457c869427402bc63 (patch) | |
tree | baa804a74e866af1714879cd34feea75a7700cda /generic/tclStubInit.c | |
parent | 258e927279e1a28d29a07a1c07ebee9a99890e69 (diff) | |
parent | 876a8aba8471fbe03407e0b3af2e44c194942141 (diff) | |
download | tcl-968face14f7b3c39dab97d0457c869427402bc63.zip tcl-968face14f7b3c39dab97d0457c869427402bc63.tar.gz tcl-968face14f7b3c39dab97d0457c869427402bc63.tar.bz2 |
[Bug 3508771] load tclreg.dll in cygwin tclsh
Implement TclWinGetTclInstance, TclpGetTZName,
and various others for Cygwin
Diffstat (limited to 'generic/tclStubInit.c')
-rw-r--r-- | generic/tclStubInit.c | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c index 32e9557..53b2015 100644 --- a/generic/tclStubInit.c +++ b/generic/tclStubInit.c @@ -42,21 +42,31 @@ #ifdef __CYGWIN__ +/* Trick, so we don't have to include <windows.h> here, which + * - b.t.w. - lacks this function anyway */ +#define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x00000004 +int __stdcall GetModuleHandleExW(unsigned int, const char *, void *); + #define TclWinGetPlatformId winGetPlatformId #define Tcl_WinUtfToTChar winUtfToTChar #define Tcl_WinTCharToUtf winTCharToUtf #define TclWinGetTclInstance winGetTclInstance #define TclWinNToHS winNToHS #define TclWinSetSockOpt winSetSockOpt -#define TclWinAddProcess winAddProcess #define TclpGetTZName pGetTZName #define TclWinNoBackslash winNoBackslash -#define TclWinSetInterfaces (void (*) _ANSI_ARGS_((int))) doNothing +#define TclWinSetInterfaces (void (*) (int)) doNothing +#define TclWinAddProcess (void (*) (void *, unsigned int)) doNothing #define TclWinFlushDirtyChannels doNothing #define TclWinResetInterfaces doNothing static Tcl_Encoding winTCharEncoding; +typedef struct ThreadSpecificData { + char tzName[64]; /* Time zone name */ +} ThreadSpecificData; +static Tcl_ThreadDataKey dataKey; + static int TclWinGetPlatformId() { @@ -65,38 +75,35 @@ TclWinGetPlatformId() return 2; /* VER_PLATFORM_WIN32_NT */; } -static int TclWinGetTclInstance() +static void *TclWinGetTclInstance() { - Tcl_Panic("TclWinGetTclInstance not yet implemented for CYGWIN"); - return 0; + void *hInstance = NULL; + GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, + (const char *)&winTCharEncoding, &hInstance); + return hInstance; } static unsigned short TclWinNToHS(unsigned short ns) { - Tcl_Panic("TclWinNToHS not yet implemented for CYGWIN"); - return (unsigned short) -1; + return ntohs(ns); } + static int -TclWinSetSockOpt(int s, int level, int optname, +TclWinSetSockOpt(void *s, int level, int optname, const char *optval, int optlen) { - Tcl_Panic("TclWinSetSockOpt not yet implemented for CYGWIN"); - return -1; -} - -static void -TclWinAddProcess(void *hProcess, unsigned long id) -{ - Tcl_Panic("TclWinAddProcess not yet implemented for CYGWIN"); + return setsockopt((int) s, level, optname, optval, optlen); } static char * TclpGetTZName(int isdst) { - /* TODO: implementation */ - Tcl_Panic("TclpGetTZName not yet implemented for CYGWIN"); - return 0; + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + const char *zone = getenv("TZ"); + Tcl_ExternalToUtf(NULL, NULL, zone, strlen(zone), 0, NULL, + tsdPtr->tzName, sizeof(tsdPtr->tzName), NULL, NULL, NULL); + return tsdPtr->tzName; } static char * @@ -158,11 +165,12 @@ Tcl_WinTCharToUtf( #elif !defined(__WIN32__) /* UNIX and MAC */ # define TclWinConvertError (void (*) _ANSI_ARGS_((unsigned int))) TclGetAndDetachPids +# undef TclWinConvertWSAError # define TclWinConvertWSAError (void (*) _ANSI_ARGS_((unsigned int))) TclpCloseFile # define TclWinGetPlatformId (int (*)()) TclpCreateTempFile -# define TclWinGetTclInstance (int (*)()) TclpCreateProcess +# define TclWinGetTclInstance (void *(*)()) TclpCreateProcess # define TclWinNToHS (unsigned short (*) _ANSI_ARGS_((unsigned short ns))) TclpMakeFile -# define TclWinSetSockOpt (int (*) _ANSI_ARGS_((int, int, int, const char *, int))) TclpOpenFile +# define TclWinSetSockOpt (int (*) _ANSI_ARGS_((void *, int, int, const char *, int))) TclpOpenFile # define TclWinAddProcess 0 # define TclpGetTZName 0 # define TclWinNoBackslash 0 |