summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rwxr-xr-xconfigure43
-rw-r--r--lib.c21
3 files changed, 69 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 022e51a6..be0fe583 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2011-11-05 Kaz Kylheku <kaz@kylheku.com>
+ Task #11442. Make work on MingW.
+
+ * configure: Test for environ and GetEnvironmentStrings.
+
+ * lib.c: Conditionally include <windows.h>.
+ (env): Implemented for POSIX and Windows with #ifdefs.
+
+2011-11-05 Kaz Kylheku <kaz@kylheku.com>
+
Task #11442. Access to environment variables.
* lib.c (env_list): New static variable.
diff --git a/configure b/configure
index ba37a922..6f98e559 100755
--- a/configure
+++ b/configure
@@ -870,6 +870,49 @@ else
fi
#
+# environ
+#
+
+printf "Checking whether we have environ ... "
+
+cat > conftest.c <<!
+int main(void)
+{
+ extern char **environ;
+ puts(environ[0]);
+ return 0;
+}
+!
+if ! make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+ printf "no\n"
+else
+ printf "yes\n"
+ printf "#define HAVE_ENVIRON 1\n" >> config.h
+fi
+
+#
+# GetEnvironmentStrings
+#
+
+printf "Checking whether we have GetEnvironmentStrings ... "
+
+cat > conftest.c <<!
+#include <windows.h>
+
+int main(void)
+{
+ WCHAR *ptr = GetEnvironmentStringsW();
+ return 0;
+}
+!
+if ! make conftest > conftest.err 2>&1 || ! [ -x conftest ] ; then
+ printf "no\n"
+else
+ printf "yes\n"
+ printf "#define HAVE_GETENVIRONMENTSTRINGS 1\n" >> config.h
+fi
+
+#
# Clean up
#
diff --git a/lib.c b/lib.c
index d874e3ab..20b793e0 100644
--- a/lib.c
+++ b/lib.c
@@ -35,6 +35,9 @@
#include <setjmp.h>
#include <wchar.h>
#include "config.h"
+#ifdef HAVE_GETENVIRONMENTSTRINGS
+#include <windows.h>
+#endif
#include "lib.h"
#include "gc.h"
#include "hash.h"
@@ -2301,18 +2304,28 @@ val set_diff(val list1, val list2, val testfun, val keyfun)
val env(void)
{
- extern char **environ;
- char **iter;
-
if (env_list) {
return env_list;
} else {
list_collect_decl (out, ptail);
+#if HAVE_ENVIRON
+ extern char **environ;
+ char **iter = environ;
- for (iter = environ; *iter != 0; iter++)
+ for (; *iter != 0; iter++)
list_collect (ptail, string_utf8(*iter));
return env_list = out;
+#elif HAVE_GETENVIRONMENTSTRINGS
+ wchar_t *env = GetEnvironmentStringsW();
+
+ for (; *env; env += wcslen(env) + 1)
+ list_collect (ptail, string(env));
+
+ return env_list = out;
+#else
+ uw_throwf(error_s, lit("string_extend: overflow"), nao);
+#endif
}
}