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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public 2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 5
6 #include <string.h> 6 #include <string.h>
7 #include "primpl.h" 7 #include "primpl.h"
8 #include "prmem.h"
9
10 #if defined(XP_UNIX)
11 #if defined(DARWIN)
12 #if defined(HAVE_CRT_EXTERNS_H)
13 #include <crt_externs.h>
14 #endif /* HAVE_CRT_EXTERNS_H */
15 #else /* DARWIN */
16 PR_IMPORT_DATA(char **) environ;
17 #endif /* DARWIN */
18 #endif /* XP_UNIX */
8 19
9 /* Lock used to lock the environment */ 20 /* Lock used to lock the environment */
10 #if defined(_PR_NO_PREEMPT) 21 #if defined(_PR_NO_PREEMPT)
11 #define _PR_NEW_LOCK_ENV() 22 #define _PR_NEW_LOCK_ENV()
12 #define _PR_DELETE_LOCK_ENV() 23 #define _PR_DELETE_LOCK_ENV()
13 #define _PR_LOCK_ENV() 24 #define _PR_LOCK_ENV()
14 #define _PR_UNLOCK_ENV() 25 #define _PR_UNLOCK_ENV()
15 #elif defined(_PR_LOCAL_THREADS_ONLY) 26 #elif defined(_PR_LOCAL_THREADS_ONLY)
16 extern _PRCPU * _pr_primordialCPU; 27 extern _PRCPU * _pr_primordialCPU;
17 static PRIntn _is; 28 static PRIntn _is;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 _PR_UNLOCK_ENV(); 62 _PR_UNLOCK_ENV();
52 return ev; 63 return ev;
53 } 64 }
54 65
55 PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) 66 PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string)
56 { 67 {
57 PRIntn result; 68 PRIntn result;
58 69
59 if (!_pr_initialized) _PR_ImplicitInitialization(); 70 if (!_pr_initialized) _PR_ImplicitInitialization();
60 71
61 if ( !strchr(string, '=')) return(PR_FAILURE); 72 if (!strchr(string, '=')) return(PR_FAILURE);
62 73
63 _PR_LOCK_ENV(); 74 _PR_LOCK_ENV();
64 result = _PR_MD_PUT_ENV(string); 75 result = _PR_MD_PUT_ENV((char*)string);
65 _PR_UNLOCK_ENV(); 76 _PR_UNLOCK_ENV();
66 return (result)? PR_FAILURE : PR_SUCCESS; 77 return result ? PR_FAILURE : PR_SUCCESS;
67 } 78 }
79
80 #if defined(XP_UNIX) && (!defined(DARWIN) || defined(HAVE_CRT_EXTERNS_H))
81 PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void)
82 {
83 char **the_environ, **result, **end, **src, **dst;
84
85 _PR_LOCK_ENV();
86 #ifdef DARWIN
87 the_environ = *(_NSGetEnviron());
88 #else
89 the_environ = environ;
90 #endif
91
92 for (end = the_environ; *end != NULL; end++)
93 /* empty loop body */;
94
95 result = (char **)PR_Malloc(sizeof(char *) * (end - the_environ + 1));
96 if (result != NULL) {
97 for (src = the_environ, dst = result; src != end; src++, dst++) {
98 size_t len;
99
100 len = strlen(*src) + 1;
101 *dst = PR_Malloc(len);
102 if (*dst == NULL) {
103 /* Allocation failed. Must clean up the half-copied env. */
104 char **to_delete;
105
106 for (to_delete = result; to_delete != dst; to_delete++) {
107 PR_Free(*to_delete);
108 }
109 PR_Free(result);
110 result = NULL;
111 goto out;
112 }
113 memcpy(*dst, *src, len);
114 }
115 *dst = NULL;
116 }
117 out:
118 _PR_UNLOCK_ENV();
119 return result;
120 }
121 #else
122 /* This platform doesn't support raw access to the environ block. */
123 PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void)
124 {
125 return NULL;
126 }
127 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698