logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

putenv.3p (4124B)


  1. '\" et
  2. .TH PUTENV "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. putenv
  12. \(em change or add a value to an environment
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdlib.h>
  17. .P
  18. int putenv(char *\fIstring\fP);
  19. .fi
  20. .SH DESCRIPTION
  21. The
  22. \fIputenv\fR()
  23. function shall use the
  24. .IR string
  25. argument to set environment variable values. The
  26. .IR string
  27. argument should point to a string of the form "\c
  28. .IR name =\c
  29. .IR value \c
  30. \&".
  31. The
  32. \fIputenv\fR()
  33. function shall make the value of the environment variable
  34. .IR name
  35. equal to
  36. .IR value
  37. by altering an existing variable or creating a new one. In either
  38. case, the string pointed to by
  39. .IR string
  40. shall become part of the environment, so altering the string shall
  41. change the environment.
  42. .P
  43. The
  44. \fIputenv\fR()
  45. function need not be thread-safe.
  46. .SH "RETURN VALUE"
  47. Upon successful completion,
  48. \fIputenv\fR()
  49. shall return 0; otherwise, it shall return a non-zero value and set
  50. .IR errno
  51. to indicate the error.
  52. .SH ERRORS
  53. The
  54. \fIputenv\fR()
  55. function may fail if:
  56. .TP
  57. .BR ENOMEM
  58. Insufficient memory was available.
  59. .LP
  60. .IR "The following sections are informative."
  61. .SH EXAMPLES
  62. .SS "Changing the Value of an Environment Variable"
  63. .P
  64. The following example changes the value of the
  65. .IR HOME
  66. environment variable to the value
  67. .BR /usr/home .
  68. .sp
  69. .RS 4
  70. .nf
  71. #include <stdlib.h>
  72. \&...
  73. static char *var = "HOME=/usr/home";
  74. int ret;
  75. .P
  76. ret = putenv(var);
  77. .fi
  78. .P
  79. .RE
  80. .SH "APPLICATION USAGE"
  81. The
  82. \fIputenv\fR()
  83. function manipulates the environment pointed to by
  84. .IR environ ,
  85. and can be used in conjunction with
  86. \fIgetenv\fR().
  87. .P
  88. See
  89. \fIexec\fR()
  90. for restrictions on changing the environment in multi-threaded
  91. applications.
  92. .P
  93. This routine may use
  94. \fImalloc\fR()
  95. to enlarge the environment.
  96. .P
  97. A potential error is to call
  98. \fIputenv\fR()
  99. with an automatic variable as the argument, then return from the
  100. calling function while
  101. .IR string
  102. is still part of the environment.
  103. .P
  104. Although the space used by
  105. .IR string
  106. is no longer used once a new string which defines
  107. .IR name
  108. is passed to
  109. \fIputenv\fR(),
  110. if any thread in the application has used
  111. \fIgetenv\fR()
  112. to retrieve a pointer to this variable, it should not be freed by calling
  113. \fIfree\fR().
  114. If the changed environment variable is one known by the system (such as
  115. the locale environment variables) the application should never free the
  116. buffer used by earlier calls to
  117. \fIputenv\fR()
  118. for the same variable.
  119. .P
  120. The
  121. \fIsetenv\fR()
  122. function is preferred over this function. One reason is that
  123. \fIputenv\fR()
  124. is optional and therefore less portable. Another is that using
  125. \fIputenv\fR()
  126. can slow down environment searches, as explained in the RATIONALE
  127. section for
  128. .IR "\fIgetenv\fR\^(\|)".
  129. .SH RATIONALE
  130. Refer to the RATIONALE section in
  131. .IR "\fIsetenv\fR\^(\|)".
  132. .SH "FUTURE DIRECTIONS"
  133. None.
  134. .SH "SEE ALSO"
  135. .IR "\fIexec\fR\^",
  136. .IR "\fIfree\fR\^(\|)",
  137. .IR "\fIgetenv\fR\^(\|)",
  138. .IR "\fImalloc\fR\^(\|)",
  139. .IR "\fIsetenv\fR\^(\|)"
  140. .P
  141. The Base Definitions volume of POSIX.1\(hy2017,
  142. .IR "\fB<stdlib.h>\fP"
  143. .\"
  144. .SH COPYRIGHT
  145. Portions of this text are reprinted and reproduced in electronic form
  146. from IEEE Std 1003.1-2017, Standard for Information Technology
  147. -- Portable Operating System Interface (POSIX), The Open Group Base
  148. Specifications Issue 7, 2018 Edition,
  149. Copyright (C) 2018 by the Institute of
  150. Electrical and Electronics Engineers, Inc and The Open Group.
  151. In the event of any discrepancy between this version and the original IEEE and
  152. The Open Group Standard, the original IEEE and The Open Group Standard
  153. is the referee document. The original Standard can be obtained online at
  154. http://www.opengroup.org/unix/online.html .
  155. .PP
  156. Any typographical or formatting errors that appear
  157. in this page are most likely
  158. to have been introduced during the conversion of the source files to
  159. man page format. To report such errors, see
  160. https://www.kernel.org/doc/man-pages/reporting_bugs.html .