about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--Src/init.c3
-rw-r--r--Src/params.c8
-rw-r--r--Src/prompt.c7
4 files changed, 14 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 6f1c4b2f4..1f507ab1f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2000-07-13  Peter Stephenson  <pws@cambridgesiliconradio.com>
 
+	* 12247: Src/init.c, Src/params.c, Src/prompt.c: remove hostnam
+	internal variable and use $HOST wherever hostname is needed.
+
 	* 12242: Fr. Br. George (George V Kouryachy) and pws:
 	Doc/Zsh/prompt.yo, Src/prompt.c: negative integers in prompt
 	escapes count from the other end of the appropriate string.
diff --git a/Src/init.c b/Src/init.c
index 5f0c98ca0..ddb6a4d65 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -595,9 +595,6 @@ setupvals(void)
     gettimeofday(&shtimer, &dummy_tz);	/* init $SECONDS */
     srand((unsigned int)(shtimer.tv_sec + shtimer.tv_usec)); /* seed $RANDOM */
 
-    hostnam     = (char *) zalloc(256);
-    gethostname(hostnam, 256);
-
     /* Set default path */
     path    = (char **) zalloc(sizeof(*path) * 5);
     path[0] = ztrdup("/bin");
diff --git a/Src/params.c b/Src/params.c
index 972922856..4f519d476 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -56,7 +56,6 @@ char **path,		/* $path        */
 /**/
 char *argzero,		/* $0           */
      *home,		/* $HOME        */
-     *hostnam,		/* $HOST        */
      *nullcmd,		/* $NULLCMD     */
      *oldpwd,		/* $OLDPWD      */
      *zoptarg,		/* $OPTARG      */
@@ -458,7 +457,7 @@ createparamtable(void)
     Param ip, pm;
     char **new_environ, **envp, **envp2, **sigptr, **t;
     char **old_environ = environ;
-    char buf[50], *str, *iname;
+    char buf[50], *str, *iname, *hostnam;
     int num_env, oae = opts[ALLEXPORT];
 #ifdef HAVE_UNAME
     struct utsname unamebuf;
@@ -494,7 +493,12 @@ createparamtable(void)
     setsparam("TMPPREFIX", ztrdup(DEFAULT_TMPPREFIX));
     setsparam("TIMEFMT", ztrdup(DEFAULT_TIMEFMT));
     setsparam("WATCHFMT", ztrdup(default_watchfmt));
+
+    hostnam = (char *)zalloc(256);
+    gethostname(hostnam, 256);
     setsparam("HOST", ztrdup(hostnam));
+    zfree(hostnam, 256);
+
     setsparam("LOGNAME", ztrdup((str = getlogin()) && *str ? str : cached_username));
 
     /* Copy the environment variables we are inheriting to dynamic *
diff --git a/Src/prompt.c b/Src/prompt.c
index 7bd4ed0f1..cca6da21f 100644
--- a/Src/prompt.c
+++ b/Src/prompt.c
@@ -201,7 +201,7 @@ promptexpand(char *s, int ns, char *rs, char *Rs)
 static int
 putpromptchar(int doprint, int endchar)
 {
-    char *ss, *tmbuf = NULL;
+    char *ss, *tmbuf = NULL, *hostnam;
     int t0, arg, test, sep;
     struct tm *tm;
     time_t timet;
@@ -372,11 +372,14 @@ putpromptchar(int doprint, int endchar)
 		bp += strlen(bp);
 		break;
 	    case 'M':
-		stradd(hostnam);
+		if ((hostnam = getsparam("HOST")))
+		    stradd(hostnam);
 		break;
 	    case 'm':
 		if (!arg)
 		    arg++;
+		if (!(hostnam = getsparam("HOST")))
+		    break;
 		if (arg < 0) {
 		    for (ss = hostnam + strlen(hostnam); ss > hostnam; ss--)
 			if (ss[-1] == '.' && !++arg)