summaryrefslogtreecommitdiff
path: root/source4/lib/replace
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-03-12 09:59:06 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:49:27 -0500
commit544a2d30e01b5f4f9849c9aa631e0525062c2707 (patch)
treebad5bc3e6465af5b78a22cf382388b4420b04fc9 /source4/lib/replace
parent9b921af12e6e26f0b0f4fa0341acfcddf68221e1 (diff)
downloadsamba-544a2d30e01b5f4f9849c9aa631e0525062c2707.tar.gz
samba-544a2d30e01b5f4f9849c9aa631e0525062c2707.tar.bz2
samba-544a2d30e01b5f4f9849c9aa631e0525062c2707.zip
r21793: add replacement for unsetenv()
metze (This used to be commit d6de7f2cda70cfd55f0f7fbb9f3b93a5a58c6f51)
Diffstat (limited to 'source4/lib/replace')
-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);