diff options
author | hobbs <hobbs> | 2007-11-29 00:31:50 (GMT) |
---|---|---|
committer | hobbs <hobbs> | 2007-11-29 00:31:50 (GMT) |
commit | 300ffcba6bfd94fe5e9afa67a61040c1974f39c3 (patch) | |
tree | 0c7765b8562e408d4234524d9ef5c431895400a9 /win | |
parent | bc12fd68ee94dccdac5e1e6d04f160cbbad550ee (diff) | |
download | tcl-300ffcba6bfd94fe5e9afa67a61040c1974f39c3.zip tcl-300ffcba6bfd94fe5e9afa67a61040c1974f39c3.tar.gz tcl-300ffcba6bfd94fe5e9afa67a61040c1974f39c3.tar.bz2 |
* win/tclWinSock.c (Tcl_GetHostName): update to previous fix to
set hostname length appropriately, clean up check overall.
Diffstat (limited to 'win')
-rw-r--r-- | win/tclWinSock.c | 56 |
1 files changed, 16 insertions, 40 deletions
diff --git a/win/tclWinSock.c b/win/tclWinSock.c index 32cfb19..eb1ee84 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinSock.c,v 1.36.2.7 2007/11/27 20:30:42 dgp Exp $ + * RCS: @(#) $Id: tclWinSock.c,v 1.36.2.8 2007/11/29 00:31:51 hobbs Exp $ */ #include "tclWinInt.h" @@ -2543,52 +2543,28 @@ Tcl_GetHostName() Tcl_MutexLock(&socketMutex); InitSockets(); - if (hostnameInitialized) { - Tcl_MutexUnlock(&socketMutex); - return hostname; - } - Tcl_MutexUnlock(&socketMutex); - - if (TclpHasSockets(NULL) == TCL_OK) { - Tcl_DString ds; - - Tcl_DStringInit(&ds); - Tcl_DStringSetLength(&ds, 255); - if (winSock.gethostname(Tcl_DStringValue(&ds), Tcl_DStringLength(&ds)) - == 0) { - Tcl_DString utfDs; - - Tcl_DStringInit(&utfDs); - Tcl_ExternalToUtfDString(NULL, Tcl_DStringValue(&ds), - Tcl_DStringLength(&ds), &utfDs); - Tcl_DStringFree(&ds); - - Tcl_MutexLock(&socketMutex); - strcpy(hostname, Tcl_DStringValue(&utfDs)); - Tcl_UtfToLower(hostname); - hostnameInitialized = 1; - Tcl_MutexUnlock(&socketMutex); - Tcl_DStringFree(&utfDs); - return hostname; - } - } - Tcl_MutexLock(&socketMutex); - length = sizeof(hostname); - if ((*tclWinProcs->getComputerNameProc)(wbuf, &length) != 0) { + if (!hostnameInitialized) { /* - * Convert string from native to UTF then change to lowercase. + * Convert hostname from native to UTF then change to lowercase. */ - Tcl_DString ds; - lstrcpynA(hostname, Tcl_WinTCharToUtf((TCHAR *) wbuf, -1, &ds), - sizeof(hostname)); + length = sizeof(hostname); + /* same as SocketsEnabled without the socketMutex lock */ + if ((winSock.hModule != NULL) + && (winSock.gethostname(hostname, length) == 0)) { + Tcl_ExternalToUtfDString(NULL, hostname, -1, &ds); + } else if ((*tclWinProcs->getComputerNameProc)(wbuf, &length) != 0) { + Tcl_WinTCharToUtf((TCHAR *) wbuf, -1, &ds); + } else { + Tcl_DStringInit(&ds); + Tcl_DStringSetLength(&ds, 0); + } + lstrcpynA(hostname, Tcl_DStringValue(&ds), sizeof(hostname)); Tcl_DStringFree(&ds); Tcl_UtfToLower(hostname); - } else { - hostname[0] = '\0'; + hostnameInitialized = 1; } - hostnameInitialized = 1; Tcl_MutexUnlock(&socketMutex); return hostname; } |