diff options
Diffstat (limited to 'source4')
-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 |