summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source4/lib/replace/README1
-rw-r--r--source4/lib/replace/libreplace.m43
-rw-r--r--source4/lib/replace/replace.c34
-rw-r--r--source4/lib/replace/replace.h5
4 files changed, 42 insertions, 1 deletions
diff --git a/source4/lib/replace/README b/source4/lib/replace/README
index 21cd0051c7..6610b7c279 100644
--- a/source4/lib/replace/README
+++ b/source4/lib/replace/README
@@ -21,6 +21,7 @@ setlinebuf
vsyslog
timegm
setenv
+unsetenv
strndup
strnlen
waitpid
diff --git a/source4/lib/replace/libreplace.m4 b/source4/lib/replace/libreplace.m4
index 805cdc6cb5..b5f931c7e4 100644
--- a/source4/lib/replace/libreplace.m4
+++ b/source4/lib/replace/libreplace.m4
@@ -263,7 +263,8 @@ AC_CHECK_HEADERS([sys/param.h limits.h])
AC_CHECK_TYPE(comparison_fn_t,
[AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
-AC_CHECK_FUNCS(strnlen setenv)
+AC_CHECK_FUNCS(setenv unsetenv)
+AC_CHECK_FUNCS(strnlen)
AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
# this test disabled as we don't actually need __VA_ARGS__ yet
diff --git a/source4/lib/replace/replace.c b/source4/lib/replace/replace.c
index 9e6c75bd35..486c1c5e13 100644
--- a/source4/lib/replace/replace.c
+++ b/source4/lib/replace/replace.c
@@ -590,6 +590,40 @@ int rep_setenv(const char *name, const char *value, int overwrite)
}
#endif
+#ifndef HAVE_UNSETENV
+int rep_unsetenv(const char *name)
+{
+ char *p;
+ size_t l1;
+ int ret;
+
+ if (!getenv(name)) {
+ return 0;
+ }
+
+ l1 = strlen(name);
+
+ p = malloc(l1+1);
+ if (p == NULL) {
+ return -1;
+ }
+ memcpy(p, name, l1);
+ p[l1] = 0;
+
+ /*
+ * use using "name" here unsets the var
+ *
+ * "name=" would set it to an empty string..
+ */
+ ret = putenv(p);
+ if (ret != 0) {
+ free(p);
+ }
+
+ return ret;
+}
+#endif
+
#ifndef HAVE_SOCKETPAIR
int rep_socketpair(int d, int type, int protocol, int sv[2])
{
diff --git a/source4/lib/replace/replace.h b/source4/lib/replace/replace.h
index 5667644025..cae9d80178 100644
--- a/source4/lib/replace/replace.h
+++ b/source4/lib/replace/replace.h
@@ -140,6 +140,11 @@ size_t rep_strnlen(const char *s, size_t n);
int rep_setenv(const char *name, const char *value, int overwrite);
#endif
+#ifndef HAVE_UNSETENV
+#define unsetenv rep_unsetenv
+int rep_unsetenv(const char *name, const char *value, int overwrite);
+#endif
+
#ifndef HAVE_SETEUID
#define seteuid rep_seteuid
int rep_seteuid(uid_t);