summaryrefslogtreecommitdiffstats
path: root/src/libnetdata/os/setenv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnetdata/os/setenv.c')
-rw-r--r--src/libnetdata/os/setenv.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/libnetdata/os/setenv.c b/src/libnetdata/os/setenv.c
index 5aa4302b8..c0de1b4b6 100644
--- a/src/libnetdata/os/setenv.c
+++ b/src/libnetdata/os/setenv.c
@@ -1,13 +1,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later
-#include "config.h"
+#include "libnetdata/libnetdata.h"
#ifndef HAVE_SETENV
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
int os_setenv(const char *name, const char *value, int overwrite) {
char *env_var;
int result;
@@ -28,3 +23,21 @@ int os_setenv(const char *name, const char *value, int overwrite) {
}
#endif
+
+void nd_setenv(const char *name, const char *value, int overwrite) {
+#if defined(OS_WINDOWS)
+ if(overwrite)
+ SetEnvironmentVariable(name, value);
+ else {
+ char buf[1024];
+ if(GetEnvironmentVariable(name, buf, sizeof(buf)) == 0)
+ SetEnvironmentVariable(name, value);
+ }
+#endif
+
+#ifdef HAVE_SETENV
+ setenv(name, value, overwrite);
+#else
+ os_setenv(name, value, overwite);
+#endif
+}