putenvのヘルプ・マニュアル
日本語 英語
putenv --help
man putenv
PUTENV(3) Linux Programmer’s Manual PUTENV(3)
名前
putenv - 環境変数の変更または追加
書式
#include
int putenv(char *string);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
putenv(): _SVID_SOURCE || _XOPEN_SOURCE
説明
putenv() 関 数 は、環境変数の追加または値の変更を行う。引数 string は
name=value という形式を取る。 name が環境に存在しない場合は string が環
境に追加される。 name が環境に存在する場合は name の値は value に変更さ
れる。 string が指している文字列は環境の一部となるので、文字列を変更 す
ると環境も変更される。
返り値
putenv() 関数は、成功した場合 0 を、エラーが発生した場合 0 以外を返す。
エラー
ENOMEM 新しい環境を割り当てるのに十分な空きがない。
準拠
SVr4, POSIX.1-2001, 4.3BSD.
注意
putenv() はリエントラントであることを求められていない。 libc4, libc5,
glibc 2.0 ではリエントラントではない。 glibc 2.1 ではリエントラントであ
る。
libc4, libc5, glibc に関する説明: もし引数 string が name 単独で、 '='
文 字 を 含 ん で い ない場合、環境変数 name は環境から除去される。もし
putenv() が新しい environ 配列を確保しなければならない時、以前の envi-
ron 配列も putenv() によって確保されたものならば、それは解放される。環
境変数そのものに割り当てられた古い記憶領域が解放されることはない。
libc4 と libc5 と glibc 2.1.2 では SUSv2 に準拠している。 putenv() で与
え られたポインタ string が使われる。この文字列は環境の一部となり、後で
変更すると環境も変わる。 (従って、 putenv() を自動変数を引数として呼 び
出し、 stringが環境の一部のままで呼び出した関数から return するとエラー
になる) しかし、glibc 2.0-2.1.1 では異なり、文字列のコピーが使われる 。
これはメモリリークを引き起こすだけでなく、 SUSv2 に違反している。これは
glibc2.1.2 で修正された。
4.4BSD バージョンでは、glibc 2.0 と同様にコピーを使う。
SUSv2 ではプロトタイプから const が取り除かれており、 glibc 2.1.3 も そ
のようになっている。
関連項目
clearenv(3), getenv(3), setenv(3), unsetenv(3), environ(7)
GNU 2007-07-26 PUTENV(3)
PUTENV(3) Linux Programmer’s Manual PUTENV(3)
NAME
putenv - change or add an environment variable
SYNOPSIS
#include
int putenv(char *string);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
putenv(): _SVID_SOURCE || _XOPEN_SOURCE
DESCRIPTION
The putenv() function adds or changes the value of environment vari-
ables. The argument string is of the form name=value. If name does
not already exist in the environment, then string is added to the envi-
ronment. If name does exist, then the value of name in the environment
is changed to value. The string pointed to by string becomes part of
the environment, so altering the string changes the environment.
RETURN VALUE
The putenv() function returns zero on success, or non-zero if an error
occurs.
ERRORS
ENOMEM Insufficient space to allocate new environment.
CONFORMING TO
SVr4, POSIX.1-2001, 4.3BSD.
NOTES
The putenv() function is not required to be reentrant, and the one in
libc4, libc5 and glibc 2.0 is not, but the glibc 2.1 version is.
Description for libc4, libc5, glibc: If the argument string is of the
form name, and does not contain an '=' character, then the variable
name is removed from the environment. If putenv() has to allocate a
new array environ, and the previous array was also allocated by
putenv(), then it will be freed. In no case will the old storage asso-
ciated to the environment variable itself be freed.
The libc4 and libc5 and glibc 2.1.2 versions conform to SUSv2: the
pointer string given to putenv() is used. In particular, this string
becomes part of the environment; changing it later will change the
environment. (Thus, it is an error is to call putenv() with an auto-
matic variable as the argument, then return from the calling function
while string is still part of the environment.) However, glibc
2.0-2.1.1 differs: a copy of the string is used. On the one hand this
causes a memory leak, and on the other hand it violates SUSv2. This
has been fixed in glibc 2.1.2.
The 4.4BSD version, like glibc 2.0, uses a copy.
SUSv2 removes the const from the prototype, and so does glibc 2.1.3.
SEE ALSO
clearenv(3), getenv(3), setenv(3), unsetenv(3), environ(7)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU 2007-07-26 PUTENV(3)