Index: nspr/pr/src/misc/prenv.c |
diff --git a/nspr/pr/src/misc/prenv.c b/nspr/pr/src/misc/prenv.c |
index 7c9f58c0193c2e38ba3992a92d20b4fe07391acb..4935f9dc78e65bbfda3cbe0edd861ef72e4dcd98 100644 |
--- a/nspr/pr/src/misc/prenv.c |
+++ b/nspr/pr/src/misc/prenv.c |
@@ -5,6 +5,17 @@ |
#include <string.h> |
#include "primpl.h" |
+#include "prmem.h" |
+ |
+#if defined(XP_UNIX) |
+#if defined(DARWIN) |
+#if defined(HAVE_CRT_EXTERNS_H) |
+#include <crt_externs.h> |
+#endif /* HAVE_CRT_EXTERNS_H */ |
+#else /* DARWIN */ |
+PR_IMPORT_DATA(char **) environ; |
+#endif /* DARWIN */ |
+#endif /* XP_UNIX */ |
/* Lock used to lock the environment */ |
#if defined(_PR_NO_PREEMPT) |
@@ -58,10 +69,59 @@ PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) |
if (!_pr_initialized) _PR_ImplicitInitialization(); |
- if ( !strchr(string, '=')) return(PR_FAILURE); |
+ if (!strchr(string, '=')) return(PR_FAILURE); |
_PR_LOCK_ENV(); |
- result = _PR_MD_PUT_ENV(string); |
+ result = _PR_MD_PUT_ENV((char*)string); |
_PR_UNLOCK_ENV(); |
- return (result)? PR_FAILURE : PR_SUCCESS; |
+ return result ? PR_FAILURE : PR_SUCCESS; |
} |
+ |
+#if defined(XP_UNIX) && (!defined(DARWIN) || defined(HAVE_CRT_EXTERNS_H)) |
+PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void) |
+{ |
+ char **the_environ, **result, **end, **src, **dst; |
+ |
+ _PR_LOCK_ENV(); |
+#ifdef DARWIN |
+ the_environ = *(_NSGetEnviron()); |
+#else |
+ the_environ = environ; |
+#endif |
+ |
+ for (end = the_environ; *end != NULL; end++) |
+ /* empty loop body */; |
+ |
+ result = (char **)PR_Malloc(sizeof(char *) * (end - the_environ + 1)); |
+ if (result != NULL) { |
+ for (src = the_environ, dst = result; src != end; src++, dst++) { |
+ size_t len; |
+ |
+ len = strlen(*src) + 1; |
+ *dst = PR_Malloc(len); |
+ if (*dst == NULL) { |
+ /* Allocation failed. Must clean up the half-copied env. */ |
+ char **to_delete; |
+ |
+ for (to_delete = result; to_delete != dst; to_delete++) { |
+ PR_Free(*to_delete); |
+ } |
+ PR_Free(result); |
+ result = NULL; |
+ goto out; |
+ } |
+ memcpy(*dst, *src, len); |
+ } |
+ *dst = NULL; |
+ } |
+ out: |
+ _PR_UNLOCK_ENV(); |
+ return result; |
+} |
+#else |
+/* This platform doesn't support raw access to the environ block. */ |
+PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void) |
+{ |
+ return NULL; |
+} |
+#endif |