1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/misc/prenv.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include <string.h> 1.10 +#include "primpl.h" 1.11 + 1.12 +/* Lock used to lock the environment */ 1.13 +#if defined(_PR_NO_PREEMPT) 1.14 +#define _PR_NEW_LOCK_ENV() 1.15 +#define _PR_DELETE_LOCK_ENV() 1.16 +#define _PR_LOCK_ENV() 1.17 +#define _PR_UNLOCK_ENV() 1.18 +#elif defined(_PR_LOCAL_THREADS_ONLY) 1.19 +extern _PRCPU * _pr_primordialCPU; 1.20 +static PRIntn _is; 1.21 +#define _PR_NEW_LOCK_ENV() 1.22 +#define _PR_DELETE_LOCK_ENV() 1.23 +#define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is); 1.24 +#define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is); 1.25 +#else 1.26 +static PRLock *_pr_envLock = NULL; 1.27 +#define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();} 1.28 +#define _PR_DELETE_LOCK_ENV() \ 1.29 + { if (_pr_envLock) { PR_DestroyLock(_pr_envLock); _pr_envLock = NULL; } } 1.30 +#define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); } 1.31 +#define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); } 1.32 +#endif 1.33 + 1.34 +/************************************************************************/ 1.35 + 1.36 +void _PR_InitEnv(void) 1.37 +{ 1.38 + _PR_NEW_LOCK_ENV(); 1.39 +} 1.40 + 1.41 +void _PR_CleanupEnv(void) 1.42 +{ 1.43 + _PR_DELETE_LOCK_ENV(); 1.44 +} 1.45 + 1.46 +PR_IMPLEMENT(char*) PR_GetEnv(const char *var) 1.47 +{ 1.48 + char *ev; 1.49 + 1.50 + if (!_pr_initialized) _PR_ImplicitInitialization(); 1.51 + 1.52 + _PR_LOCK_ENV(); 1.53 + ev = _PR_MD_GET_ENV(var); 1.54 + _PR_UNLOCK_ENV(); 1.55 + return ev; 1.56 +} 1.57 + 1.58 +PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) 1.59 +{ 1.60 + PRIntn result; 1.61 + 1.62 + if (!_pr_initialized) _PR_ImplicitInitialization(); 1.63 + 1.64 + if ( !strchr(string, '=')) return(PR_FAILURE); 1.65 + 1.66 + _PR_LOCK_ENV(); 1.67 + result = _PR_MD_PUT_ENV(string); 1.68 + _PR_UNLOCK_ENV(); 1.69 + return (result)? PR_FAILURE : PR_SUCCESS; 1.70 +}