diff options
author | Andrew Tridgell <tridge@samba.org> | 2006-08-24 00:41:15 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:16:38 -0500 |
commit | 18f93fce20162662ec16d4914320c7c6b6435ae1 (patch) | |
tree | 60d39d1328c71944cf6a258372c676286bf57723 | |
parent | fe791078b71cc103de10fc7c82302ea8ee19e447 (diff) | |
download | samba-18f93fce20162662ec16d4914320c7c6b6435ae1.tar.gz samba-18f93fce20162662ec16d4914320c7c6b6435ae1.tar.bz2 samba-18f93fce20162662ec16d4914320c7c6b6435ae1.zip |
r17764: more portable setenv() replacement
(This used to be commit 5c00b6d08324b46cd7025264c0320352d2842ead)
-rw-r--r-- | source4/lib/ldb/replace/replace.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/source4/lib/ldb/replace/replace.c b/source4/lib/ldb/replace/replace.c index e2df7fe363..faa5771a76 100644 --- a/source4/lib/ldb/replace/replace.c +++ b/source4/lib/ldb/replace/replace.c @@ -70,17 +70,31 @@ #ifndef HAVE_SETENV int setenv(const char *name, const char *value, int overwrite) { - char *p = NULL; - int ret = -1; + char *p; + size_t l1, l2; + int ret; - asprintf(&p, "%s=%s", name, value); + if (!overwrite && getenv(name)) { + return 0; + } + + l1 = strlen(name); + l2 = strlen(value); + + p = malloc(l1+l2+2); + if (p == NULL) { + return -1; + } + memcpy(p, name, l1); + p[l1] = '='; + memcpy(p+l1+1, value, l2); + p[l1+l2+1] = 0; - if (overwrite || getenv(name)) { - if (p) ret = putenv(p); - } else { - ret = 0; + ret = putenv(p); + if (ret != 0) { + free(p); } - return ret; + return ret; } #endif |