andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef prenv_h___ andre@0: #define prenv_h___ andre@0: andre@0: #include "prtypes.h" andre@0: andre@0: /*******************************************************************************/ andre@0: /*******************************************************************************/ andre@0: /****************** THESE FUNCTIONS MAY NOT BE THREAD SAFE *********************/ andre@0: /*******************************************************************************/ andre@0: /*******************************************************************************/ andre@0: andre@0: PR_BEGIN_EXTERN_C andre@0: andre@0: /* andre@0: ** PR_GetEnv() -- Retrieve value of environment variable andre@0: ** andre@0: ** Description: andre@0: ** PR_GetEnv() is modeled on Unix getenv(). andre@0: ** andre@0: ** andre@0: ** Inputs: andre@0: ** var -- The name of the environment variable andre@0: ** andre@0: ** Returns: andre@0: ** The value of the environment variable 'var' or NULL if andre@0: ** the variable is undefined. andre@0: ** andre@0: ** Restrictions: andre@0: ** You'd think that a POSIX getenv(), putenv() would be andre@0: ** consistently implemented everywhere. Surprise! It is not. On andre@0: ** some platforms, a putenv() where the argument is of andre@0: ** the form "name" causes the named environment variable to andre@0: ** be un-set; that is: a subsequent getenv() returns NULL. On andre@0: ** other platforms, the putenv() fails, on others, it is a andre@0: ** no-op. Similarly, a putenv() where the argument is of the andre@0: ** form "name=" causes the named environment variable to be andre@0: ** un-set; a subsequent call to getenv() returns NULL. On andre@0: ** other platforms, a subsequent call to getenv() returns a andre@0: ** pointer to a null-string (a byte of zero). andre@0: ** andre@0: ** PR_GetEnv(), PR_SetEnv() provide a consistent behavior andre@0: ** across all supported platforms. There are, however, some andre@0: ** restrictions and some practices you must use to achieve andre@0: ** consistent results everywhere. andre@0: ** andre@0: ** When manipulating the environment there is no way to un-set andre@0: ** an environment variable across all platforms. We suggest andre@0: ** you interpret the return of a pointer to null-string to andre@0: ** mean the same as a return of NULL from PR_GetEnv(). andre@0: ** andre@0: ** A call to PR_SetEnv() where the parameter is of the form andre@0: ** "name" will return PR_FAILURE; the environment remains andre@0: ** unchanged. A call to PR_SetEnv() where the parameter is andre@0: ** of the form "name=" may un-set the envrionment variable on andre@0: ** some platforms; on others it may set the value of the andre@0: ** environment variable to the null-string. andre@0: ** andre@0: ** For example, to test for NULL return or return of the andre@0: ** null-string from PR_GetEnv(), use the following code andre@0: ** fragment: andre@0: ** andre@0: ** char *val = PR_GetEnv("foo"); andre@0: ** if ((NULL == val) || ('\0' == *val)) { andre@0: ** ... interpret this as un-set ... andre@0: ** } andre@0: ** andre@0: ** The caller must ensure that the string passed andre@0: ** to PR_SetEnv() is persistent. That is: The string should andre@0: ** not be on the stack, where it can be overwritten andre@0: ** on return from the function calling PR_SetEnv(). andre@0: ** Similarly, the string passed to PR_SetEnv() must not be andre@0: ** overwritten by other actions of the process. ... Some andre@0: ** platforms use the string by reference rather than copying andre@0: ** it into the environment space. ... You have been warned! andre@0: ** andre@0: ** Use of platform-native functions that manipulate the andre@0: ** environment (getenv(), putenv(), andre@0: ** SetEnvironmentVariable(), etc.) must not be used with andre@0: ** NSPR's similar functions. The platform-native functions andre@0: ** may not be thread safe and/or may operate on different andre@0: ** conceptual environment space than that operated upon by andre@0: ** NSPR's functions or other environment manipulating andre@0: ** functions on the same platform. (!) andre@0: ** andre@0: */ andre@0: NSPR_API(char*) PR_GetEnv(const char *var); andre@0: andre@0: /* andre@0: ** PR_SetEnv() -- set, unset or change an environment variable andre@0: ** andre@0: ** Description: andre@0: ** PR_SetEnv() is modeled on the Unix putenv() function. andre@0: ** andre@0: ** Inputs: andre@0: ** string -- pointer to a caller supplied andre@0: ** constant, persistent string of the form name=value. Where andre@0: ** name is the name of the environment variable to be set or andre@0: ** changed; value is the value assigned to the variable. andre@0: ** andre@0: ** Returns: andre@0: ** PRStatus. andre@0: ** andre@0: ** Restrictions: andre@0: ** See the Restrictions documented in the description of andre@0: ** PR_GetEnv() in this header file. andre@0: ** andre@0: ** andre@0: */ andre@0: NSPR_API(PRStatus) PR_SetEnv(const char *string); andre@0: andre@0: PR_END_EXTERN_C andre@0: andre@0: #endif /* prenv_h___ */