diff options
author | stanton <stanton@noemail.net> | 1999-04-16 00:46:29 (GMT) |
---|---|---|
committer | stanton <stanton@noemail.net> | 1999-04-16 00:46:29 (GMT) |
commit | 98569293dc21e22480004e4e3f2ce85ec0bfd80f (patch) | |
tree | ce9959f2747257d98d52ec8d18bf3b0de99b9535 /unix/tclUnixSock.c | |
parent | 6a4a1d8213f4de5bce0eaafa8f4d86117022bf1a (diff) | |
download | tcl-98569293dc21e22480004e4e3f2ce85ec0bfd80f.zip tcl-98569293dc21e22480004e4e3f2ce85ec0bfd80f.tar.gz tcl-98569293dc21e22480004e4e3f2ce85ec0bfd80f.tar.bz2 |
merged tcl 8.1 branch back into the main trunk
FossilOrigin-Name: f3b32fb71c9011ac220779bd9dbe5617c9dc87d9
Diffstat (limited to 'unix/tclUnixSock.c')
-rw-r--r-- | unix/tclUnixSock.c | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 2013e8f..37d430e 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.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: tclUnixSock.c,v 1.3 1999/03/10 05:52:52 stanton Exp $ + * RCS: @(#) $Id: tclUnixSock.c,v 1.4 1999/04/16 00:48:05 stanton Exp $ */ #include "tcl.h" @@ -41,6 +41,8 @@ static char hostname[TCL_HOSTNAME_LEN + 1]; static int hostnameInited = 0; +TCL_DECLARE_MUTEX(hostMutex) + /* *---------------------------------------------------------------------- @@ -66,43 +68,53 @@ Tcl_GetHostName() #ifndef NO_UNAME struct utsname u; struct hostent *hp; +#else + char buffer[sizeof(hostname)]; #endif + CONST char *native; + Tcl_MutexLock(&hostMutex); if (hostnameInited) { + Tcl_MutexUnlock(&hostMutex); return hostname; } + native = NULL; #ifndef NO_UNAME (VOID *) memset((VOID *) &u, (int) 0, sizeof(struct utsname)); - if (uname(&u) > -1) { - hp = gethostbyname(u.nodename); + if (uname(&u) > -1) { /* INTL: Native. */ + hp = gethostbyname(u.nodename); /* INTL: Native. */ if (hp != NULL) { - strcpy(hostname, hp->h_name); + native = hp->h_name; } else { - strcpy(hostname, u.nodename); + native = u.nodename; } - hostnameInited = 1; - return hostname; } #else /* * Uname doesn't exist; try gethostname instead. */ - if (gethostname(hostname, sizeof(hostname)) > -1) { - hostnameInited = 1; - return hostname; + if (gethostname(buffer, sizeof(buffer)) > -1) { /* INTL: Native. */ + native = buffer; } #endif - hostname[0] = 0; + if (native == NULL) { + hostname[0] = 0; + } else { + Tcl_ExternalToUtf(NULL, NULL, native, -1, 0, NULL, hostname, + sizeof(hostname), NULL, NULL, NULL); + } + hostnameInited = 1; + Tcl_MutexUnlock(&hostMutex); return hostname; } /* *---------------------------------------------------------------------- * - * TclHasSockets -- + * TclpHasSockets -- * * Detect if sockets are available on this platform. * @@ -116,7 +128,7 @@ Tcl_GetHostName() */ int -TclHasSockets(interp) +TclpHasSockets(interp) Tcl_Interp *interp; /* Not used. */ { return TCL_OK; |