prenv.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef prenv_h___
  38. #define prenv_h___
  39. #include "prtypes.h"
  40. /*******************************************************************************/
  41. /*******************************************************************************/
  42. /****************** THESE FUNCTIONS MAY NOT BE THREAD SAFE *********************/
  43. /*******************************************************************************/
  44. /*******************************************************************************/
  45. PR_BEGIN_EXTERN_C
  46. /*
  47. ** PR_GetEnv() -- Retrieve value of environment variable
  48. **
  49. ** Description:
  50. ** PR_GetEnv() is modeled on Unix getenv().
  51. **
  52. **
  53. ** Inputs:
  54. ** var -- The name of the environment variable
  55. **
  56. ** Returns:
  57. ** The value of the environment variable 'var' or NULL if
  58. ** the variable is undefined.
  59. **
  60. ** Restrictions:
  61. ** You'd think that a POSIX getenv(), putenv() would be
  62. ** consistently implemented everywhere. Surprise! It is not. On
  63. ** some platforms, a putenv() where the argument is of
  64. ** the form "name" causes the named environment variable to
  65. ** be un-set; that is: a subsequent getenv() returns NULL. On
  66. ** other platforms, the putenv() fails, on others, it is a
  67. ** no-op. Similarly, a putenv() where the argument is of the
  68. ** form "name=" causes the named environment variable to be
  69. ** un-set; a subsequent call to getenv() returns NULL. On
  70. ** other platforms, a subsequent call to getenv() returns a
  71. ** pointer to a null-string (a byte of zero).
  72. **
  73. ** PR_GetEnv(), PR_SetEnv() provide a consistent behavior
  74. ** across all supported platforms. There are, however, some
  75. ** restrictions and some practices you must use to achieve
  76. ** consistent results everywhere.
  77. **
  78. ** When manipulating the environment there is no way to un-set
  79. ** an environment variable across all platforms. We suggest
  80. ** you interpret the return of a pointer to null-string to
  81. ** mean the same as a return of NULL from PR_GetEnv().
  82. **
  83. ** A call to PR_SetEnv() where the parameter is of the form
  84. ** "name" will return PR_FAILURE; the environment remains
  85. ** unchanged. A call to PR_SetEnv() where the parameter is
  86. ** of the form "name=" may un-set the envrionment variable on
  87. ** some platforms; on others it may set the value of the
  88. ** environment variable to the null-string.
  89. **
  90. ** For example, to test for NULL return or return of the
  91. ** null-string from PR_GetEnv(), use the following code
  92. ** fragment:
  93. **
  94. ** char *val = PR_GetEnv("foo");
  95. ** if ((NULL == val) || ('\0' == *val)) {
  96. ** ... interpret this as un-set ...
  97. ** }
  98. **
  99. ** The caller must ensure that the string passed
  100. ** to PR_SetEnv() is persistent. That is: The string should
  101. ** not be on the stack, where it can be overwritten
  102. ** on return from the function calling PR_SetEnv().
  103. ** Similarly, the string passed to PR_SetEnv() must not be
  104. ** overwritten by other actions of the process. ... Some
  105. ** platforms use the string by reference rather than copying
  106. ** it into the environment space. ... You have been warned!
  107. **
  108. ** Use of platform-native functions that manipulate the
  109. ** environment (getenv(), putenv(),
  110. ** SetEnvironmentVariable(), etc.) must not be used with
  111. ** NSPR's similar functions. The platform-native functions
  112. ** may not be thread safe and/or may operate on different
  113. ** conceptual environment space than that operated upon by
  114. ** NSPR's functions or other environment manipulating
  115. ** functions on the same platform. (!)
  116. **
  117. */
  118. NSPR_API(char*) PR_GetEnv(const char *var);
  119. /*
  120. ** PR_SetEnv() -- set, unset or change an environment variable
  121. **
  122. ** Description:
  123. ** PR_SetEnv() is modeled on the Unix putenv() function.
  124. **
  125. ** Inputs:
  126. ** string -- pointer to a caller supplied
  127. ** constant, persistent string of the form name=value. Where
  128. ** name is the name of the environment variable to be set or
  129. ** changed; value is the value assigned to the variable.
  130. **
  131. ** Returns:
  132. ** PRStatus.
  133. **
  134. ** Restrictions:
  135. ** See the Restrictions documented in the description of
  136. ** PR_GetEnv() in this header file.
  137. **
  138. **
  139. */
  140. NSPR_API(PRStatus) PR_SetEnv(const char *string);
  141. /*
  142. ** DEPRECATED. Use PR_SetEnv() instead.
  143. */
  144. #ifdef XP_MAC
  145. NSPR_API(PRIntn) PR_PutEnv(const char *string);
  146. #endif
  147. PR_END_EXTERN_C
  148. #endif /* prenv_h___ */