os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclUnixSock.c
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/unix/tclUnixSock.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,173 @@
1.4 +/*
1.5 + * tclUnixSock.c --
1.6 + *
1.7 + * This file contains Unix-specific socket related code.
1.8 + *
1.9 + * Copyright (c) 1995 Sun Microsystems, Inc.
1.10 + * Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.
1.11 + *
1.12 + * See the file "license.terms" for information on usage and redistribution
1.13 + * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
1.14 + *
1.15 + * RCS: @(#) $Id: tclUnixSock.c,v 1.6.2.4 2006/09/07 09:01:07 vasiljevic Exp $
1.16 + */
1.17 +
1.18 +#include "tcl.h"
1.19 +#include "tclPort.h"
1.20 +
1.21 +/*
1.22 + * There is no portable macro for the maximum length
1.23 + * of host names returned by gethostbyname(). We should only
1.24 + * trust SYS_NMLN if it is at least 255 + 1 bytes to comply with DNS
1.25 + * host name limits.
1.26 + *
1.27 + * Note: SYS_NMLN is a restriction on "uname" not on gethostbyname!
1.28 + *
1.29 + * For example HP-UX 10.20 has SYS_NMLN == 9, while gethostbyname()
1.30 + * can return a fully qualified name from DNS of up to 255 bytes.
1.31 + *
1.32 + * Fix suggested by Viktor Dukhovni (viktor@esm.com)
1.33 + */
1.34 +
1.35 +#if defined(SYS_NMLN) && SYS_NMLEN >= 256
1.36 +#define TCL_HOSTNAME_LEN SYS_NMLEN
1.37 +#else
1.38 +#define TCL_HOSTNAME_LEN 256
1.39 +#endif
1.40 +
1.41 +
1.42 +/*
1.43 + * The following variable holds the network name of this host.
1.44 + */
1.45 +
1.46 +static char hostname[TCL_HOSTNAME_LEN + 1];
1.47 +static int hostnameInited = 0;
1.48 +TCL_DECLARE_MUTEX(hostMutex)
1.49 +
1.50 +
1.51 +/*
1.52 + *----------------------------------------------------------------------
1.53 + *
1.54 + * Tcl_GetHostName --
1.55 + *
1.56 + * Returns the name of the local host.
1.57 + *
1.58 + * Results:
1.59 + * A string containing the network name for this machine, or
1.60 + * an empty string if we can't figure out the name. The caller
1.61 + * must not modify or free this string.
1.62 + *
1.63 + * Side effects:
1.64 + * None.
1.65 + *
1.66 + *----------------------------------------------------------------------
1.67 + */
1.68 +
1.69 +EXPORT_C CONST char *
1.70 +Tcl_GetHostName()
1.71 +{
1.72 +#ifndef NO_UNAME
1.73 + struct utsname u;
1.74 + struct hostent *hp;
1.75 +#else
1.76 + char buffer[sizeof(hostname)];
1.77 +#endif
1.78 + CONST char *native;
1.79 +
1.80 + Tcl_MutexLock(&hostMutex);
1.81 + if (hostnameInited) {
1.82 + Tcl_MutexUnlock(&hostMutex);
1.83 + return hostname;
1.84 + }
1.85 +
1.86 + native = NULL;
1.87 +#ifndef NO_UNAME
1.88 + (VOID *) memset((VOID *) &u, (int) 0, sizeof(struct utsname));
1.89 + if (uname(&u) > -1) { /* INTL: Native. */
1.90 + hp = TclpGetHostByName(u.nodename); /* INTL: Native. */
1.91 + if (hp == NULL) {
1.92 + /*
1.93 + * Sometimes the nodename is fully qualified, but gets truncated
1.94 + * as it exceeds SYS_NMLN. See if we can just get the immediate
1.95 + * nodename and get a proper answer that way.
1.96 + */
1.97 + char *dot = strchr(u.nodename, '.');
1.98 + if (dot != NULL) {
1.99 + char *node = ckalloc((unsigned) (dot - u.nodename + 1));
1.100 + memcpy(node, u.nodename, (size_t) (dot - u.nodename));
1.101 + node[dot - u.nodename] = '\0';
1.102 + hp = TclpGetHostByName(node);
1.103 + ckfree(node);
1.104 + }
1.105 + }
1.106 + if (hp != NULL) {
1.107 + native = hp->h_name;
1.108 + } else {
1.109 + native = u.nodename;
1.110 + }
1.111 + }
1.112 +#else
1.113 + /*
1.114 + * Uname doesn't exist; try gethostname instead.
1.115 + */
1.116 +
1.117 + if (gethostname(buffer, sizeof(buffer)) > -1) { /* INTL: Native. */
1.118 + native = buffer;
1.119 + }
1.120 +#endif
1.121 +
1.122 + if (native == NULL) {
1.123 + hostname[0] = 0;
1.124 + } else {
1.125 + Tcl_ExternalToUtf(NULL, NULL, native, -1, 0, NULL, hostname,
1.126 + sizeof(hostname), NULL, NULL, NULL);
1.127 + }
1.128 + hostnameInited = 1;
1.129 + Tcl_MutexUnlock(&hostMutex);
1.130 + return hostname;
1.131 +}
1.132 +
1.133 +/*
1.134 + *----------------------------------------------------------------------
1.135 + *
1.136 + * TclpHasSockets --
1.137 + *
1.138 + * Detect if sockets are available on this platform.
1.139 + *
1.140 + * Results:
1.141 + * Returns TCL_OK.
1.142 + *
1.143 + * Side effects:
1.144 + * None.
1.145 + *
1.146 + *----------------------------------------------------------------------
1.147 + */
1.148 +
1.149 +int
1.150 +TclpHasSockets(interp)
1.151 + Tcl_Interp *interp; /* Not used. */
1.152 +{
1.153 + return TCL_OK;
1.154 +}
1.155 +
1.156 +/*
1.157 + *----------------------------------------------------------------------
1.158 + *
1.159 + * TclpFinalizeSockets --
1.160 + *
1.161 + * Performs per-thread socket subsystem finalization.
1.162 + *
1.163 + * Results:
1.164 + * None.
1.165 + *
1.166 + * Side effects:
1.167 + * None.
1.168 + *
1.169 + *----------------------------------------------------------------------
1.170 + */
1.171 +
1.172 +void
1.173 +TclpFinalizeSockets()
1.174 +{
1.175 + return;
1.176 +}