aboutsummaryrefslogtreecommitdiff
path: root/src/lib/cfuns-c.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/cfuns-c.c')
-rw-r--r--src/lib/cfuns-c.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lib/cfuns-c.c b/src/lib/cfuns-c.c
index d7eae316..4a1e596f 100644
--- a/src/lib/cfuns-c.c
+++ b/src/lib/cfuns-c.c
@@ -439,3 +439,30 @@ oa_system(const char* cmd)
return system(cmd);
}
+
+
+/* Return the value of an environment variable. */
+OPENAXIOM_EXPORT char*
+oa_getenv(const char* var)
+{
+#ifdef __MINGW32__
+#define BUFSIZE 128
+ char* buf = (char*) malloc(BUFSIZE);
+ int len = GetEnvironmentVariable(var, buf, BUFSIZE);
+ if (len == 0) {
+ free(buf);
+ return NULL;
+ }
+ else if (len > BUFSIZE) {
+ buf = (char*) realloc(len);
+ len = GetEnvironmentVariable(var, buf, len);
+ if (len == 0) {
+ free(buf);
+ return NULL;
+ }
+ }
+ return buf;
+#else
+ return getenv(var);
+#endif
+}