Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Unified Diff: nspr/pr/src/misc/prenv.c

Issue 1504923011: Update NSS to 3.21 RTM and NSPR to 4.11 RTM (Closed) Base URL: http://src.chromium.org/svn/trunk/deps/third_party/nss
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698