From d770252d3a6dfe5e97d1a6846e2e5bfde92accc2 Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Mon, 22 Nov 1999 16:11:05 +1100 Subject: [PATCH] - Added a setenv replacement for systems which lack it --- ChangeLog | 1 + configure.in | 2 +- helper.c | 21 +++++++++++++++++++++ helper.h | 4 ++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index d7ea7b761..0f069dfd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ - Fix EGD problems (Thanks to Ben Taylor ) - Retry /dev/urandom reads interrupted by signal (report from Robert Hardy ) + - Added a setenv replacement for systems which lack it 19991121 - OpenBSD CVS Changes: diff --git a/configure.in b/configure.in index 0678fa4c8..a831b9210 100644 --- a/configure.in +++ b/configure.in @@ -58,7 +58,7 @@ dnl Checks for header files. AC_CHECK_HEADERS(pty.h endian.h paths.h lastlog.h shadow.h netgroup.h maillock.h sys/select.h sys/time.h) dnl Checks for library functions. -AC_CHECK_FUNCS(openpty strlcpy strlcat mkdtemp arc4random setproctitle setlogin) +AC_CHECK_FUNCS(openpty strlcpy strlcat mkdtemp arc4random setproctitle setlogin setenv) AC_CHECK_FUNC(login, [AC_DEFINE(HAVE_LOGIN)], diff --git a/helper.c b/helper.c index 47e797b6c..91a78b577 100644 --- a/helper.c +++ b/helper.c @@ -149,3 +149,24 @@ void setproctitle(const char *fmt, ...) /* FIXME */ } #endif /* !HAVE_SETPROCTITLE */ + +#ifndef HAVE_SETENV +int setenv(const char *name, const char *value, int overwrite) +{ + char *env_string; + int result; + + /* Don't overwrite existing env. var if overwrite is 0 */ + if (!overwrite && (getenv(name) != NULL)) + return(0); + + env_string = xmalloc(strlen(name) + strlen(value) + 2); + sprintf(env_string, "%s=%s", name, value); + + result = putenv(env_string); + + xfree(env_string); + + return(result); +} +#endif /* !HAVE_SETENV */ diff --git a/helper.h b/helper.h index 0e53fac43..68e0a8530 100644 --- a/helper.h +++ b/helper.h @@ -47,4 +47,8 @@ void arc4random_stir(void); void setproctitle(const char *fmt, ...); #endif /* !HAVE_SETPROCTITLE */ +#ifndef HAVE_SETENV +int setenv(const char *name, const char *value, int overwrite); +#endif /* !HAVE_SETENV */ + #endif /* _HELPER_H */