From 4dcf9fa0521a1c4243c28fb2f657d8029317e55e Mon Sep 17 00:00:00 2001
From: Laurent Bercot
A few functions in env.h (and many in exec.h) @@ -53,13 +53,13 @@ environment variables, or to remove them from the environment.
-char const *env_get (char const *s)
+char const *env_get (char const *s)
Deprecated alias of
getenv().
-char const *ucspi_get (char const *s)
+char const *ucspi_get (char const *s)
Prepends the current UCSPI protocol
to s and returns that environment variable. For instance,
uscpi_get("REMOTEEUID") would return the contents of the environment
@@ -69,7 +69,7 @@ if the variable that was specifically requested is not found.
-char const *env_get2 (char const *const *envp, char const *s)
+char const *env_get2 (char const *const *envp, char const *s)
Similar to getenv(), but searches in envp instead of the current
process's environment.
Despite the name, these functions also work for argvs.
-size_t env_len (char const *const* envp)
-Returns the number of elements in the array of strings envp up (but
-not including) the first null pointer.
+size_t env_len (char const *const* envp)
+Returns the number of elements in the array of strings envp up to, but
+not including, the first null pointer.
-int env_string (stralloc *sa, char const *const *envp, size_t envlen)
+int env_string (stralloc *sa, char const *const *envp, size_t envlen)
Serializes the array of NUL-terminated strings envp with envlen
elements into a series of contiguous NUL-terminated strings in the stralloc
*sa.
-int env_make (char const **v, size_t argc, char const *s, size_t len)
+int env_make (char const **v, size_t n, char const *s, size_t len)
Deserializes the result of env_string: pointers to the first
-argc contiguous NUL-terminated strings contained in the byte-string
+n contiguous NUL-terminated strings contained in the byte-string
s of length len are written to v. Returns 1 on
-success, or 0 EINVAL if s does not end in a NUL.
+success, or 0 EINVAL if s does not end in a NUL.
Note that this function does not write NULL to the final value of v.
-int env_addmodif (stralloc *sa, char const *s, char const *t)
+int env_addmodif (stralloc *sa, char const *s, char const *t)
Adds an instruction to the modif contained in *sa. If t is
null, add an instruction to remove the variable s from the
environment. If t is not null, add an instruction to always set the
@@ -111,16 +111,17 @@ variable s to t.
-size_t env_merge (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen)
+size_t env_merge (char const **v, size_t vmax, char const *const *envp, size_t envlen, char const *modifs, size_t modiflen)
Takes the environment with envlen variables contained in envp,
applies the modifications encoded in the modif modifs of length
-modiflen, and stores the result in v. It only tries to store
-up to vmax variables. Returns the number of elements now in
+modiflen, and stores the result in v with a terminating NULL.
+It only tries to store up to vmax-1 variables, which makes vmax
+entries after the terminating NULL. Returns the number of elements now in
v, or 0 if the resulting v would be larger than vmax.
-size_t env_merg (char const **v, size_t vmax, char const *const *envp, char const *modifs, size_t modiflen)
+size_t env_merg (char const **v, size_t vmax, char const *const *envp, char const *modifs, size_t modiflen)
Similar to the above function, but envp is assumed to be NULL
terminated.
-int envdir_internal (char const *path, stralloc *modifs, unsigned int options, char nullis)
+int envdir_internal (char const *path, stralloc *modifs, unsigned int options, char nullis)
Essentially s6-envdir as library.
options is a bitwise OR of SKALIBS_ENVDIR_VERBATIM,
SKALIBS_ENVDIR_NOCHOMP and SKALIBS_ENVDIR_NOCLAMP, which
@@ -140,21 +141,21 @@ the program it executes.
-int envdir_chomp (char const *path, stralloc *modifs)
+int envdir_chomp (char const *path, stralloc *modifs)
A macro that calls
envdir_internal(path, modifs, SKALIBS_ENVDIR_NOCHOMP, '\n').
int envdir (char const *path, stralloc *modifs)
-int envdir_verbatim (char const *path, stralloc *modifs)
-int envdir_verbatim_chomp (char const *path, stralloc *modifs)
+int envdir_verbatim (char const *path, stralloc *modifs)
+int envdir_verbatim_chomp (char const *path, stralloc *modifs)
Macros that call envdir_internal(path, modifs, options, '\n'), with
options set to self-explanatory values.
-int env_dump (char const *dir, mode_t mode, char const *const *envp)
+int env_dump (char const *dir, mode_t mode, char const *const *envp)
Turns the contents of the NULL terminated environment in envp into an
envdir located at dir. Files are created with mode mode.