Lisp_Object Vshell_file_name;
-#ifndef MAINTAIN_ENVIRONMENT
-/* List of strings to append to front of environment of
- all subprocesses when they are started. */
-
Lisp_Object Vprocess_environment;
-#endif
/* True iff we are about to fork off a synchronous process or if we
are waiting for it. */
#endif
CHECK_STRING (args[0], 0);
- if (nargs <= 1 || NULL (args[1]))
+ if (nargs <= 1 || NILP (args[1]))
args[1] = build_string ("/dev/null");
else
args[1] = Fexpand_file_name (args[1], current_buffer->directory);
}
/* Search for program; barf if not found. */
openp (Vexec_path, args[0], "", &path, 1);
- if (NULL (path))
+ if (NILP (path))
{
close (filefd);
report_file_error ("Searching for program", Fcons (args[0], Qnil));
register int fd1 = fd[1];
char **env;
-#ifdef MAINTAIN_ENVIRONMENT
- env = (char **) alloca (size_of_current_environ ());
- get_current_environ (env);
-#else
env = environ;
-#endif /* MAINTAIN_ENVIRONMENT */
#if 0 /* Some systems don't have sigblock. */
mask = sigblock (sigmask (SIGCHLD));
while ((nread = read (fd[0], buf, sizeof buf)) > 0)
{
immediate_quit = 0;
- if (!NULL (buffer))
+ if (!NILP (buffer))
insert (buf, nread);
- if (!NULL (display) && INTERACTIVE)
+ if (!NILP (display) && INTERACTIVE)
redisplay_preserve_echo_area ();
immediate_quit = 1;
QUIT;
Fwrite_region (start, end, filename_string, Qnil, Qlambda);
record_unwind_protect (delete_temp_file, filename_string);
- if (!NULL (args[3]))
+ if (!NILP (args[3]))
Fdelete_region (start, end);
args[3] = filename_string;
Fcons (current_buffer->directory, Qnil));
}
-#ifndef MAINTAIN_ENVIRONMENT
/* Set `env' to a vector of the strings in Vprocess_environment. */
{
register Lisp_Object tem;
*new_env++ = (char *) XSTRING (XCONS (tem)->car)->data;
*new_env = 0;
}
-#endif /* Not MAINTAIN_ENVIRONMENT */
close (0);
close (1);
_exit (1);
}
+static int
+getenv_internal (var, varlen, value, valuelen)
+ char *var;
+ int varlen;
+ char **value;
+ int **valuelen;
+{
+ Lisp_Object scan;
+
+ for (scan = Vprocess_environment; CONSP (scan); scan = XCONS (scan)->cdr)
+ {
+ Lisp_Object entry = XCONS (scan)->car;
+
+ if (XTYPE (entry) == Lisp_String
+ && XSTRING (entry)->size > varlen
+ && XSTRING (entry)->data[varlen] == '='
+ && ! bcmp (XSTRING (entry)->data, var, varlen))
+ {
+ *value = XSTRING (entry)->data + (varlen + 1);
+ *valuelen = XSTRING (entry)->size - (varlen + 1);
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+DEFUN ("getenv", Fgetenv, Sgetenv, 1, 2, 0,
+ "Return the value of environment variable VAR, as a string.\n\
+VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
+This function consults the variable ``process-environment'' for its value.")
+ (var)
+ Lisp_Object var;
+{
+ char *value;
+ int valuelen;
+
+ CHECK_STRING (var, 0);
+ if (getenv_internal (XSTRING (var)->data, XSTRING (var)->size,
+ &value, &valuelen))
+ return make_string (value, valuelen);
+ else
+ return Qnil;
+}
+
+/* A version of getenv that consults process_environment, easily
+ callable from C. */
+char *
+egetenv (var)
+{
+ char *value;
+ int valuelen;
+
+ if (getenv_internal (var, strlen (var), &value, &valuelen))
+ return value;
+ else
+ return 0;
+}
+
#endif /* not VMS */
\f
init_callproc ()
#ifdef VMS
Vshell_file_name = build_string ("*dcl*");
#else
- sh = (char *) egetenv ("SHELL");
+ sh = (char *) getenv ("SHELL");
Vshell_file_name = build_string (sh ? sh : "/bin/sh");
#endif
-#ifndef MAINTAIN_ENVIRONMENT
- /* The equivalent of this operation was done
- in init_environ in environ.c if MAINTAIN_ENVIRONMENT */
Vprocess_environment = Qnil;
#ifndef CANNOT_DUMP
if (initialized)
for (envp = environ; *envp; envp++)
Vprocess_environment = Fcons (build_string (*envp),
Vprocess_environment);
-#endif /* MAINTAIN_ENVIRONMENT */
}
syms_of_callproc ()
"Directory of architecture-independent files that come with GNU Emacs,\n\
intended for Emacs to use.");
-#ifndef MAINTAIN_ENVIRONMENT
DEFVAR_LISP ("process-environment", &Vprocess_environment,
- "List of strings to append to environment of subprocesses that are started.\n\
-Each string should have the format ENVVARNAME=VALUE.");
-#endif
+ "List of environment variables for subprocesses to inherit.\n\
+Each element should be a string of the form ENVVARNAME=VALUE.\n\
+The environment which Emacs inherits is placed in this variable\n\
+when Emacs starts.");
#ifndef VMS
defsubr (&Scall_process);
#endif
+ defsubr (&Sgetenv);
defsubr (&Scall_process_region);
}