commit a8e40d0287f05f6e444035431b1cc7b340fe8d79
parent 8cd0d07171f8b32553ef0c6936fd5737adcb4bab
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Fri, 22 Dec 2017 16:44:47 +0000
Deprecate env_get
Diffstat:
9 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/package/deps.mak b/package/deps.mak
@@ -263,17 +263,17 @@ src/libstddjb/cdb_read.o src/libstddjb/cdb_read.lo: src/libstddjb/cdb_read.c src
src/libstddjb/cdb_successor.o src/libstddjb/cdb_successor.lo: src/libstddjb/cdb_successor.c src/include/skalibs/cdb.h
src/libstddjb/cdb_zero.o src/libstddjb/cdb_zero.lo: src/libstddjb/cdb_zero.c src/include/skalibs/cdb.h
src/libstddjb/child_spawn.o src/libstddjb/child_spawn.lo: src/libstddjb/child_spawn.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h src/include/skalibs/types.h
-src/libstddjb/child_spawn0.o src/libstddjb/child_spawn0.lo: src/libstddjb/child_spawn0.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h
-src/libstddjb/child_spawn1_internal.o src/libstddjb/child_spawn1_internal.lo: src/libstddjb/child_spawn1_internal.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h
+src/libstddjb/child_spawn0.o src/libstddjb/child_spawn0.lo: src/libstddjb/child_spawn0.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h
+src/libstddjb/child_spawn1_internal.o src/libstddjb/child_spawn1_internal.lo: src/libstddjb/child_spawn1_internal.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h
src/libstddjb/child_spawn1_pipe.o src/libstddjb/child_spawn1_pipe.lo: src/libstddjb/child_spawn1_pipe.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h
src/libstddjb/child_spawn1_socket.o src/libstddjb/child_spawn1_socket.lo: src/libstddjb/child_spawn1_socket.c src/libstddjb/djbunix-internal.h src/include/skalibs/djbunix.h src/include/skalibs/webipc.h
-src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_spawn2.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h
+src/libstddjb/child_spawn2.o src/libstddjb/child_spawn2.lo: src/libstddjb/child_spawn2.c src/include/skalibs/allreadwrite.h src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/sig.h src/include/skalibs/strerr2.h src/include/skalibs/sysdeps.h
src/libstddjb/coe.o src/libstddjb/coe.lo: src/libstddjb/coe.c src/include/skalibs/djbunix.h
src/libstddjb/deepsleepuntil.o src/libstddjb/deepsleepuntil.lo: src/libstddjb/deepsleepuntil.c src/include/skalibs/iopause.h src/include/skalibs/tai.h
src/libstddjb/dir_close.o src/libstddjb/dir_close.lo: src/libstddjb/dir_close.c src/include/skalibs/direntry.h
src/libstddjb/dir_fd.o src/libstddjb/dir_fd.lo: src/libstddjb/dir_fd.c src/include/skalibs/direntry.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h
src/libstddjb/env_addmodif.o src/libstddjb/env_addmodif.lo: src/libstddjb/env_addmodif.c src/include/skalibs/env.h src/include/skalibs/stralloc.h
-src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c src/include/skalibs/env.h src/include/skalibs/posixplz.h
+src/libstddjb/env_get.o src/libstddjb/env_get.lo: src/libstddjb/env_get.c src/include/skalibs/posixplz.h
src/libstddjb/env_get2.o src/libstddjb/env_get2.lo: src/libstddjb/env_get2.c src/include/skalibs/bytestr.h src/include/skalibs/env.h
src/libstddjb/env_len.o src/libstddjb/env_len.lo: src/libstddjb/env_len.c src/include/skalibs/env.h
src/libstddjb/env_make.o src/libstddjb/env_make.lo: src/libstddjb/env_make.c src/include/skalibs/env.h
@@ -438,7 +438,7 @@ src/libstddjb/pathexec0_run.o src/libstddjb/pathexec0_run.lo: src/libstddjb/path
src/libstddjb/pathexec_fromenv.o src/libstddjb/pathexec_fromenv.lo: src/libstddjb/pathexec_fromenv.c src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/stralloc.h
src/libstddjb/pathexec_r.o src/libstddjb/pathexec_r.lo: src/libstddjb/pathexec_r.c src/include/skalibs/djbunix.h
src/libstddjb/pathexec_r_name.o src/libstddjb/pathexec_r_name.lo: src/libstddjb/pathexec_r_name.c src/include/skalibs/bytestr.h src/include/skalibs/djbunix.h src/include/skalibs/env.h
-src/libstddjb/pathexec_run.o src/libstddjb/pathexec_run.lo: src/libstddjb/pathexec_run.c src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/env.h src/include/skalibs/posixplz.h
+src/libstddjb/pathexec_run.o src/libstddjb/pathexec_run.lo: src/libstddjb/pathexec_run.c src/include/skalibs/config.h src/include/skalibs/djbunix.h src/include/skalibs/posixplz.h
src/libstddjb/pipe_internal.o src/libstddjb/pipe_internal.lo: src/libstddjb/pipe_internal.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h
src/libstddjb/prog.o src/libstddjb/prog.lo: src/libstddjb/prog.c src/include/skalibs/strerr2.h
src/libstddjb/prot.o src/libstddjb/prot.lo: src/libstddjb/prot.c src/include/skalibs/djbunix.h
diff --git a/src/include/skalibs/env.h b/src/include/skalibs/env.h
@@ -1,14 +1,14 @@
/* ISC license. */
-#ifndef ENV_H
-#define ENV_H
+#ifndef SKALIBS_ENV_H
+#define SKALIBS_ENV_H
#include <sys/types.h>
#include <skalibs/gccattributes.h>
#include <skalibs/stralloc.h>
extern size_t env_len (char const *const *) gccattr_pure ;
-extern char const *env_get (char const *) gccattr_pure ;
+extern char const *env_get (char const *) gccattr_deprecated ;
extern char const *env_get2 (char const *const *, char const *) gccattr_pure ;
extern char const *ucspi_get (char const *) gccattr_pure ;
extern int env_addmodif (stralloc *, char const *, char const *) ;
diff --git a/src/libstddjb/child_spawn.c b/src/libstddjb/child_spawn.c
@@ -10,10 +10,6 @@
#include <unistd.h>
#include <errno.h>
#include <signal.h>
-#include <skalibs/types.h>
-#include <skalibs/allreadwrite.h>
-#include <skalibs/env.h>
-#include <skalibs/djbunix.h>
#ifdef SKALIBS_HASPOSIXSPAWN
@@ -28,8 +24,10 @@
#endif
-#define NOFDVAR "SKALIBS_CHILD_SPAWN_FDS"
-
+#include <skalibs/types.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/env.h>
+#include <skalibs/djbunix.h>
/*
If n = 0 : child's stdin and stdout are the same as the parent's
@@ -48,10 +46,10 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const
int p[n ? n : 1][2] ;
pid_t pid ;
int e ;
- size_t m = sizeof(NOFDVAR) ;
+ size_t m = sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR) ;
unsigned int i = 0 ;
char modifs[m + 1 + n * UINT_FMT] ;
- memcpy(modifs, NOFDVAR "=", sizeof(NOFDVAR)) ;
+ memcpy(modifs, SKALIBS_CHILD_SPAWN_FDS_ENVVAR "=", sizeof(SKALIBS_CHILD_SPAWN_FDS_ENVVAR)) ;
for (; i < n ; i++) if (pipe(p[i]) < 0) { e = errno ; goto errpi ; }
for (i = 0 ; i < n ; i++)
if ((ndelay_on(p[i][i & 1]) < 0) || (coe(p[i][i & 1]) < 0))
@@ -94,7 +92,7 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const
if (e) goto erractions ;
}
{
- int haspath = !!env_get("PATH") ;
+ int haspath = !!getenv("PATH") ;
size_t envlen = env_len(envp) ;
char const *newenv[envlen + 2] ;
if (!env_merge(newenv, envlen+2, envp, envlen, modifs, m)) goto errsp ;
@@ -137,8 +135,8 @@ pid_t child_spawn (char const *prog, char const *const *argv, char const *const
syncdie:
{
- unsigned char c = errno ;
- fd_write(syncpipe[1], (char const *)&c, 1) ;
+ char c = errno ;
+ fd_write(syncpipe[1], &c, 1) ;
}
_exit(127) ;
}
diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c
@@ -9,14 +9,13 @@
#include <spawn.h>
#include <stdlib.h>
#include <skalibs/config.h>
-#include <skalibs/env.h>
pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const *envp)
{
posix_spawnattr_t attr ;
int e ;
pid_t pid ;
- int haspath = !!env_get("PATH") ;
+ int haspath = !!getenv("PATH") ;
e = posix_spawnattr_init(&attr) ;
if (e) goto err ;
{
diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libstddjb/child_spawn1_internal.c
@@ -3,7 +3,6 @@
#include <skalibs/sysdeps.h>
#include <unistd.h>
#include <errno.h>
-#include <skalibs/djbunix.h>
#ifdef SKALIBS_HASPOSIXSPAWN
@@ -11,7 +10,7 @@
#include <spawn.h>
#include <stdlib.h>
#include <skalibs/config.h>
-#include <skalibs/env.h>
+#include <skalibs/djbunix.h>
pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to)
{
@@ -19,7 +18,7 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con
posix_spawnattr_t attr ;
int e ;
pid_t pid ;
- int haspath = !!env_get("PATH") ;
+ int haspath = !!getenv("PATH") ;
if (coe(p[!(to & 1)]) < 0) { e = errno ; goto err ; }
e = posix_spawnattr_init(&attr) ;
if (e) goto err ;
@@ -69,6 +68,7 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con
#include <skalibs/allreadwrite.h>
#include <skalibs/strerr2.h>
#include <skalibs/sig.h>
+#include <skalibs/djbunix.h>
pid_t child_spawn1_internal (char const *prog, char const *const *argv, char const *const *envp, int *p, int to)
{
diff --git a/src/libstddjb/child_spawn2.c b/src/libstddjb/child_spawn2.c
@@ -9,14 +9,12 @@
#include <unistd.h>
#include <errno.h>
#include <signal.h>
-#include <skalibs/djbunix.h>
#ifdef SKALIBS_HASPOSIXSPAWN
#include <stdlib.h>
#include <spawn.h>
#include <skalibs/config.h>
-#include <skalibs/env.h>
#else
@@ -27,6 +25,8 @@
#endif
+#include <skalibs/djbunix.h>
+
pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const *envp, int *fds)
{
#ifdef SKALIBS_HASPOSIXSPAWN
@@ -65,7 +65,7 @@ pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const
e = posix_spawn_file_actions_addclose(&actions, p[0][1]) ;
if (e) goto erractions ;
{
- int haspath = !!env_get("PATH") ;
+ int haspath = !!getenv("PATH") ;
if (!haspath && (setenv("PATH", SKALIBS_DEFAULTPATH, 0) < 0))
{
e = errno ; goto erractions ;
@@ -98,8 +98,8 @@ pid_t child_spawn2 (char const *prog, char const *const *argv, char const *const
syncdie:
{
- unsigned char c = errno ;
- fd_write(syncpipe[1], (char const *)&c, 1) ;
+ char c = errno ;
+ fd_write(syncpipe[1], &c, 1) ;
}
_exit(127) ;
}
diff --git a/src/libstddjb/env_get.c b/src/libstddjb/env_get.c
@@ -1,9 +1,9 @@
/* ISC license. */
-#include <skalibs/env.h>
+#include <stdlib.h>
#include <skalibs/posixplz.h>
char const *env_get (char const *s)
{
- return env_get2((char const **)environ, s) ;
+ return getenv(s) ;
}
diff --git a/src/libstddjb/pathexec_run.c b/src/libstddjb/pathexec_run.c
@@ -1,13 +1,13 @@
/* ISC license. */
+#include <stdlib.h>
#include <skalibs/config.h>
-#include <skalibs/env.h>
#include <skalibs/posixplz.h>
#include <skalibs/djbunix.h>
void pathexec_run (char const *file, char const *const *argv, char const *const *envp)
{
- char const *path = env_get("PATH") ;
+ char const *path = getenv("PATH") ;
if (!path) path = SKALIBS_DEFAULTPATH ;
execvep(file, argv, envp, path) ;
}
diff --git a/src/libstddjb/ucspi_get.c b/src/libstddjb/ucspi_get.c
@@ -2,11 +2,12 @@
#include <errno.h>
#include <string.h>
+#include <stdlib.h>
#include <skalibs/env.h>
char const *ucspi_get (char const *s)
{
- char const *x = env_get("PROTO") ;
+ char const *x = getenv("PROTO") ;
if (x)
{
size_t len = strlen(s) ;
@@ -14,7 +15,7 @@ char const *ucspi_get (char const *s)
char tmp[len + xlen + 1] ;
memcpy(tmp, x, xlen) ;
memcpy(tmp + xlen, s, len + 1) ;
- x = env_get(tmp) ;
+ x = getenv(tmp) ;
if (!x) errno = ENOENT ;
}
else errno = EINVAL ;