- environ = envinit;
- strncat(homedir, pwd->pw_dir, sizeof(homedir)-6);
- strncat(shell, pwd->pw_shell, sizeof(shell)-7);
- if (term[strlen("TERM=")] == 0)
- strncat(term, stypeof(ttyn), sizeof(term)-6);
- strncat(user, pwd->pw_name, sizeof(user)-6);
+ /* destroy environment unless user has asked to preserve it */
+ if (!pflag)
+ environ = envinit;
+
+ /* set up environment, this time without destruction */
+ /* copy the environment before setenving */
+ i = 0;
+ while (environ[i] != NULL)
+ i++;
+ envnew = (char **) malloc(sizeof (char *) * (i + 1));
+ for (; i >= 0; i--)
+ envnew[i] = environ[i];
+ environ = envnew;
+
+ setenv("HOME=", pwd->pw_dir, 1);
+ setenv("SHELL=", pwd->pw_shell, 1);
+ if (term[0] == '\0')
+ strncpy(term, stypeof(tty), sizeof(term));
+ setenv("TERM=", term, 0);
+ setenv("USER=", pwd->pw_name, 1);
+ setenv("PATH=", ":/usr/ucb:/bin:/usr/bin", 0);
+