summaryrefslogtreecommitdiff
path: root/rts/posix/GetEnv.c
diff options
context:
space:
mode:
authorDuncan Coutts <duncan@well-typed.com>2011-05-26 18:44:41 +0100
committerDuncan Coutts <duncan@well-typed.com>2011-05-26 18:47:38 +0100
commite8832eb9f05ca46d9315250c3baf7010eb0630a4 (patch)
treebe08e88284b463362f14673175aedca35bcfcb8c /rts/posix/GetEnv.c
parent43c7d555c8d7eea6ba0d76bce33be8d25a01c6fd (diff)
downloadhaskell-e8832eb9f05ca46d9315250c3baf7010eb0630a4.tar.gz
Emit various bits of OS process info into the eventlog
The process ID, parent process ID, rts name and version The program arguments and environment.
Diffstat (limited to 'rts/posix/GetEnv.c')
-rw-r--r--rts/posix/GetEnv.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/rts/posix/GetEnv.c b/rts/posix/GetEnv.c
new file mode 100644
index 0000000000..4d5c7e248e
--- /dev/null
+++ b/rts/posix/GetEnv.c
@@ -0,0 +1,44 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team 2011
+ *
+ * Access to the process environment variables
+ *
+ * ---------------------------------------------------------------------------*/
+
+#include "Rts.h"
+#include "GetEnv.h"
+
+#if defined(darwin_HOST_OS)
+
+/* While the "extern char** environ" var does exist on OSX, it is not
+ * available to shared libs. See ghc ticket #2458 and
+ * http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
+ */
+#include <crt_externs.h>
+
+static char** get_environ(void) { return *(_NSGetEnviron()); }
+
+#else
+
+/* On proper unix systems the environ is just a global var.
+ */
+extern char** environ;
+static char** get_environ(void) { return environ; }
+
+#endif
+
+
+void getProgEnvv(int *out_envc, char **out_envv[]) {
+ int envc;
+ char **environ = get_environ();
+
+ for (envc = 0; environ[envc] != NULL; envc++) {};
+
+ *out_envc = envc;
+ *out_envv = environ;
+}
+
+void freeProgEnvv(int envc STG_UNUSED, char *envv[] STG_UNUSED) {
+ /* nothing */
+}