From 6fdb0f034ecd0bffddcc56ccf6fc1e97d073b806 Mon Sep 17 00:00:00 2001 From: Araq Date: Tue, 8 Mar 2011 23:44:50 +0100 Subject: fixes #17; I hope! --- lib/pure/os.nim | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 5f50578c0..2d234473b 100755 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -41,8 +41,8 @@ when defined(Nimdoc): # only for proper documentation: ## For example: '.' for POSIX or ':' for the classic Macintosh. ParDir* = ".." - ## The constant string used by the operating system to refer to the parent - ## directory. + ## The constant string used by the operating system to refer to the + ## parent directory. ## ## For example: ".." for POSIX or "::" for the classic Macintosh. @@ -699,12 +699,25 @@ when defined(windows): discard FreeEnvironmentStringsA(env) else: - var gEnv {.importc: "environ".}: cstringArray - # var gEnv {.importc: "gEnv".}: cstringArray + when defined(macosx): + # From the manual: + # Shared libraries and bundles don't have direct access to environ, + # which is only available to the loader ld(1) when a complete program + # is being linked. + # The environment routines can still be used, but if direct access to + # environ is needed, the _NSGetEnviron() routine, defined in + # , can be used to retrieve the address of environ + # at runtime. + proc NSGetEnviron(): cstringArray {. + importc: "_NSGetEnviron", header: "".} + else: + var gEnv {.importc: "environ".}: cstringArray proc getEnvVarsC() = # retrieves the variables of char** env of C's main proc if not envComputed: + when defined(macosx): + var gEnv = NSGetEnviron() var i = 0 while True: if gEnv[i] == nil: break -- cgit 1.4.1-2-gfad0