Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include <string.h> |
michael@0 | 7 | #include "primpl.h" |
michael@0 | 8 | |
michael@0 | 9 | /* Lock used to lock the environment */ |
michael@0 | 10 | #if defined(_PR_NO_PREEMPT) |
michael@0 | 11 | #define _PR_NEW_LOCK_ENV() |
michael@0 | 12 | #define _PR_DELETE_LOCK_ENV() |
michael@0 | 13 | #define _PR_LOCK_ENV() |
michael@0 | 14 | #define _PR_UNLOCK_ENV() |
michael@0 | 15 | #elif defined(_PR_LOCAL_THREADS_ONLY) |
michael@0 | 16 | extern _PRCPU * _pr_primordialCPU; |
michael@0 | 17 | static PRIntn _is; |
michael@0 | 18 | #define _PR_NEW_LOCK_ENV() |
michael@0 | 19 | #define _PR_DELETE_LOCK_ENV() |
michael@0 | 20 | #define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is); |
michael@0 | 21 | #define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is); |
michael@0 | 22 | #else |
michael@0 | 23 | static PRLock *_pr_envLock = NULL; |
michael@0 | 24 | #define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();} |
michael@0 | 25 | #define _PR_DELETE_LOCK_ENV() \ |
michael@0 | 26 | { if (_pr_envLock) { PR_DestroyLock(_pr_envLock); _pr_envLock = NULL; } } |
michael@0 | 27 | #define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); } |
michael@0 | 28 | #define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); } |
michael@0 | 29 | #endif |
michael@0 | 30 | |
michael@0 | 31 | /************************************************************************/ |
michael@0 | 32 | |
michael@0 | 33 | void _PR_InitEnv(void) |
michael@0 | 34 | { |
michael@0 | 35 | _PR_NEW_LOCK_ENV(); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | void _PR_CleanupEnv(void) |
michael@0 | 39 | { |
michael@0 | 40 | _PR_DELETE_LOCK_ENV(); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | PR_IMPLEMENT(char*) PR_GetEnv(const char *var) |
michael@0 | 44 | { |
michael@0 | 45 | char *ev; |
michael@0 | 46 | |
michael@0 | 47 | if (!_pr_initialized) _PR_ImplicitInitialization(); |
michael@0 | 48 | |
michael@0 | 49 | _PR_LOCK_ENV(); |
michael@0 | 50 | ev = _PR_MD_GET_ENV(var); |
michael@0 | 51 | _PR_UNLOCK_ENV(); |
michael@0 | 52 | return ev; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) |
michael@0 | 56 | { |
michael@0 | 57 | PRIntn result; |
michael@0 | 58 | |
michael@0 | 59 | if (!_pr_initialized) _PR_ImplicitInitialization(); |
michael@0 | 60 | |
michael@0 | 61 | if ( !strchr(string, '=')) return(PR_FAILURE); |
michael@0 | 62 | |
michael@0 | 63 | _PR_LOCK_ENV(); |
michael@0 | 64 | result = _PR_MD_PUT_ENV(string); |
michael@0 | 65 | _PR_UNLOCK_ENV(); |
michael@0 | 66 | return (result)? PR_FAILURE : PR_SUCCESS; |
michael@0 | 67 | } |