aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKarl Heuer1994-06-15 05:29:08 +0000
committerKarl Heuer1994-06-15 05:29:08 +0000
commitc0c868359c0ac57496fb547fd4e5e40d1aafdc88 (patch)
treeaaeb90ba023a056d4eee6def51be95f99b0d4a35 /src
parentac98827760f17ccb3497fcad97acac3947013531 (diff)
downloademacs-c0c868359c0ac57496fb547fd4e5e40d1aafdc88.tar.gz
emacs-c0c868359c0ac57496fb547fd4e5e40d1aafdc88.zip
(init_system_name): New function, replaces get_system_name.
Diffstat (limited to 'src')
-rw-r--r--src/sysdep.c172
1 files changed, 74 insertions, 98 deletions
diff --git a/src/sysdep.c b/src/sysdep.c
index cb8ee1cfaae..bcc50e3d432 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -1958,17 +1958,14 @@ end_of_data ()
1958 1958
1959#endif /* not CANNOT_DUMP */ 1959#endif /* not CANNOT_DUMP */
1960 1960
1961/* get_system_name returns as its value 1961/* init_system_name sets up the string for the Lisp function
1962 a string for the Lisp function system-name to return. */ 1962 system-name to return. */
1963 1963
1964#ifdef BSD4_1 1964#ifdef BSD4_1
1965#include <whoami.h> 1965#include <whoami.h>
1966#endif 1966#endif
1967 1967
1968/* Can't have this within the function since `static' is #defined to 1968extern Lisp_Object Vsystem_name;
1969 nothing for some USG systems. */
1970static char *get_system_name_cache;
1971static int get_system_name_predump_p;
1972 1969
1973#ifndef BSD4_1 1970#ifndef BSD4_1
1974#ifndef VMS 1971#ifndef VMS
@@ -1979,116 +1976,95 @@ static int get_system_name_predump_p;
1979#endif /* not VMS */ 1976#endif /* not VMS */
1980#endif /* not BSD4_1 */ 1977#endif /* not BSD4_1 */
1981 1978
1982char * 1979void
1983get_system_name () 1980init_system_name ()
1984{ 1981{
1985#ifdef BSD4_1 1982#ifdef BSD4_1
1986 return sysname; 1983 Vsystem_name = build_string (sysname);
1987#else 1984#else
1988#ifndef CANNOT_DUMP
1989 /* If the cached value is from before the dump, and we've dumped
1990 since then, then the cached value is no good. */
1991 if (get_system_name_predump_p && initialized && get_system_name_cache)
1992 {
1993 xfree (get_system_name_cache);
1994 get_system_name_cache = 0;
1995 }
1996#endif
1997 if (!get_system_name_cache)
1998 {
1999 /* No cached value, so get the name from the system. */
2000#ifdef VMS 1985#ifdef VMS
2001 char *sp; 1986 char *sp, *end;
2002 if ((sp = egetenv ("SYS$NODE")) == 0) 1987 if ((sp = egetenv ("SYS$NODE")) == 0)
2003 sp = "vax-vms"; 1988 Vsystem_name = build_string ("vax-vms");
2004 else 1989 else if ((end = index (sp, ':')) == 0)
2005 { 1990 Vsystem_name = build_string (sp);
2006 char *end; 1991 else
2007 1992 Vsystem_name = make_string (sp, end - sp);
2008 if ((end = index (sp, ':')) != 0)
2009 *end = '\0';
2010 }
2011 get_system_name_cache = (char *) xmalloc (strlen (sp) + 1);
2012 strcpy (get_system_name_cache, sp);
2013#else 1993#else
2014#ifndef HAVE_GETHOSTNAME 1994#ifndef HAVE_GETHOSTNAME
2015 struct utsname uts; 1995 struct utsname uts;
2016 uname (&uts); 1996 uname (&uts);
2017 get_system_name_cache = (char *) xmalloc (strlen (uts.nodename) + 1); 1997 Vsystem_name = build_string (uts.nodename);
2018 strcpy (get_system_name_cache, uts.nodename);
2019#else /* HAVE_GETHOSTNAME */ 1998#else /* HAVE_GETHOSTNAME */
2020 { 1999 int hostname_size = 256;
2021 int hostname_size = 256; 2000 char *hostname = (char *) alloca (hostname_size);
2022 char *hostname = (char *) xmalloc (hostname_size); 2001
2023 2002 /* Try to get the host name; if the buffer is too short, try
2024 /* Try to get the host name; if the buffer is too short, try 2003 again. Apparently, the only indication gethostname gives of
2025 again. Apparently, the only indication gethostname gives of 2004 whether the buffer was large enough is the presence or absence
2026 whether the buffer was large enough is the presence or absence 2005 of a '\0' in the string. Eech. */
2027 of a '\0' in the string. Eech. */ 2006 for (;;)
2028 for (;;) 2007 {
2029 { 2008 gethostname (hostname, hostname_size - 1);
2030 gethostname (hostname, hostname_size - 1); 2009 hostname[hostname_size - 1] = '\0';
2031 hostname[hostname_size - 1] = '\0';
2032 2010
2033 /* Was the buffer large enough for the '\0'? */ 2011 /* Was the buffer large enough for the '\0'? */
2034 if (strlen (hostname) < hostname_size - 1) 2012 if (strlen (hostname) < hostname_size - 1)
2035 break; 2013 break;
2036 2014
2037 hostname_size <<= 1; 2015 hostname_size <<= 1;
2038 hostname = (char *) xrealloc (hostname, hostname_size); 2016 hostname = (char *) alloca (hostname_size);
2039 } 2017 }
2040 get_system_name_cache = hostname;
2041#ifdef HAVE_SOCKETS 2018#ifdef HAVE_SOCKETS
2042 /* Turn the hostname into the official, fully-qualified hostname. 2019 /* Turn the hostname into the official, fully-qualified hostname.
2043 Don't do this if we're going to dump; this can confuse system 2020 Don't do this if we're going to dump; this can confuse system
2044 libraries on some machines and make the dumped emacs core dump. */ 2021 libraries on some machines and make the dumped emacs core dump. */
2045#ifndef CANNOT_DUMP 2022#ifndef CANNOT_DUMP
2046 if (initialized) 2023 if (initialized)
2047#endif /* not CANNOT_DUMP */ 2024#endif /* not CANNOT_DUMP */
2048 { 2025 {
2049 struct hostent *hp = gethostbyname (hostname); 2026 struct hostent *hp = gethostbyname (hostname);
2050 if (hp) 2027 if (hp)
2051 { 2028 {
2052 char *fqdn = hp->h_name; 2029 char *fqdn = hp->h_name;
2053 char *p; 2030 char *p;
2054 2031
2055 if (!index (fqdn, '.')) 2032 if (!index (fqdn, '.'))
2056 { 2033 {
2057 /* We still don't have a fully qualified domain name. 2034 /* We still don't have a fully qualified domain name.
2058 Try to find one in the list of alternate names */ 2035 Try to find one in the list of alternate names */
2059 char **alias = hp->h_aliases; 2036 char **alias = hp->h_aliases;
2060 while (*alias && !index (*alias, '.')) 2037 while (*alias && !index (*alias, '.'))
2061 alias++; 2038 alias++;
2062 if (*alias) 2039 if (*alias)
2063 fqdn = *alias; 2040 fqdn = *alias;
2064 } 2041 }
2065 hostname = (char *) xrealloc (hostname, strlen (fqdn) + 1); 2042 hostname = fqdn;
2066 strcpy (hostname, fqdn);
2067#if 0 2043#if 0
2068 /* Convert the host name to lower case. */ 2044 /* Convert the host name to lower case. */
2069 /* Using ctype.h here would introduce a possible locale 2045 /* Using ctype.h here would introduce a possible locale
2070 dependence that is probably wrong for hostnames. */ 2046 dependence that is probably wrong for hostnames. */
2071 p = hostname 2047 p = hostname;
2072 while (*p) 2048 while (*p)
2073 { 2049 {
2074 if (*p >= 'A' && *p <= 'Z') 2050 if (*p >= 'A' && *p <= 'Z')
2075 *p += 'a' - 'A'; 2051 *p += 'a' - 'A';
2076 p++; 2052 p++;
2077 } 2053 }
2078#endif 2054#endif
2079 } 2055 }
2080 } 2056 }
2081#endif /* HAVE_SOCKETS */ 2057#endif /* HAVE_SOCKETS */
2082 get_system_name_cache = hostname; 2058 Vsystem_name = build_string (hostname);
2083 }
2084#endif /* HAVE_GETHOSTNAME */ 2059#endif /* HAVE_GETHOSTNAME */
2085#endif /* VMS */ 2060#endif /* VMS */
2086#ifndef CANNOT_DUMP
2087 get_system_name_predump_p = !initialized;
2088#endif
2089 }
2090 return (get_system_name_cache);
2091#endif /* BSD4_1 */ 2061#endif /* BSD4_1 */
2062 {
2063 unsigned char *p;
2064 for (p = XSTRING (Vsystem_name)->data; *p; p++)
2065 if (*p == ' ' || *p == '\t')
2066 *p = '-';
2067 }
2092} 2068}
2093 2069
2094#ifndef VMS 2070#ifndef VMS