Get types in osFreeMBlocks in sync with osGetMBlocks
[ghc.git] / rts / posix / GetEnv.c
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team 2011
4 *
5 * Access to the process environment variables
6 *
7 * ---------------------------------------------------------------------------*/
8
9 #include "Rts.h"
10 #include "GetEnv.h"
11
12 #if defined(darwin_HOST_OS)
13
14 /* While the "extern char** environ" var does exist on OSX, it is not
15 * available to shared libs. See ghc ticket #2458 and
16 * http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
17 */
18 #include <crt_externs.h>
19
20 static char** get_environ(void) { return *(_NSGetEnviron()); }
21
22 #else
23
24 /* On proper unix systems the environ is just a global var.
25 */
26 extern char** environ;
27 static char** get_environ(void) { return environ; }
28
29 #endif
30
31
32 void getProgEnvv(int *out_envc, char **out_envv[]) {
33 int envc;
34 char **environ = get_environ();
35
36 for (envc = 0; environ[envc] != NULL; envc++) {};
37
38 *out_envc = envc;
39 *out_envv = environ;
40 }
41
42 void freeProgEnvv(int envc STG_UNUSED, char *envv[] STG_UNUSED) {
43 /* nothing */
44 }