diff options
author | stanton <stanton> | 1999-04-16 00:46:29 (GMT) |
---|---|---|
committer | stanton <stanton> | 1999-04-16 00:46:29 (GMT) |
commit | 97464e6cba8eb0008cf2727c15718671992b913f (patch) | |
tree | ce9959f2747257d98d52ec8d18bf3b0de99b9535 /unix/tclUnixSock.c | |
parent | a8c96ddb94d1483a9de5e340b740cb74ef6cafa7 (diff) | |
download | tcl-97464e6cba8eb0008cf2727c15718671992b913f.zip tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.gz tcl-97464e6cba8eb0008cf2727c15718671992b913f.tar.bz2 |
merged tcl 8.1 branch back into the main trunk
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; |