setenvのヘルプ・マニュアル
日本語 英語
setenv --help
man setenv
SETENV(3) Linux Programmer’s Manual SETENV(3)
名前
setenv - 環境変数を変更または追加する
書式
#include
int setenv(const char *name, const char *value, int overwrite);
int unsetenv(const char *name);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
setenv(), unsetenv(): _BSD_SOURCE || _POSIX_C_SOURCE >= 200112L ||
_XOPEN_SOURCE >= 600
説明
setenv() 関数は、name が存在しない場合環境変数 name に値 value を設定し
、環境に追加する。 name が環境に存在する場合、overwrite が 0 以外ならば
その値を value に変更し、overwrite が 0 ならば name の値を変更しない 。
こ の関数は、 (putenv(3) と違い) name と value により参照される文字列の
コピーを行う。
unsetenv() 関数は、変数 name を環境から削除する。 name が環境にない場合
、この関数は成功し、環境は変更されない。
返り値
setenv() 関数は、成功すると 0 を返す。環境に十分な空きが無い場合は -1
を返す。
unsetenv() 関数は、成功すると 0 を返す。エラーの場合は -1 を 返 し 、
errno を設定してエラーの原因を示す。
エラー
EINVAL name に '=' 文字が含まれている。
準拠
4.3BSD, POSIX.1-2001.
注意
POSIX.1-2001 は、 setenv() や unsetenv() がリエントラント (再入可能) で
あることを要求していない。
glibc 2.2.2 以前では、 unsetenv() は返り値が void のプロトタイプであ っ
た 。 も っ と 最 近の glibc 版は、「書式」セクションで示しているように
POSIX.1-2001 互換のプロトタイプである。
バグ
POSIX.1-2001 では 「name に '=' 文字が含まれる場合、 setenv() はエラ ー
EINVAL で失敗すべきである」と述べられている。しかし 2.3.4 より前のバー
ジョンの glibc では、 name に '=' 文字が含まれるのを許している。
関連項目
clearenv(3), getenv(3), putenv(3), environ(7)
GNU 2007-07-26 SETENV(3)
SETENV(3) Linux Programmer’s Manual SETENV(3)
NAME
setenv - change or add an environment variable
SYNOPSIS
#include
int setenv(const char *name, const char *value, int overwrite);
int unsetenv(const char *name);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
setenv(), unsetenv(): _BSD_SOURCE || _POSIX_C_SOURCE >= 200112L ||
_XOPEN_SOURCE >= 600
DESCRIPTION
The setenv() function adds the variable name to the environment with
the value value, if name does not already exist. If name does exist in
the environment, then its value is changed to value if overwrite is
non-zero; if overwrite is zero, then the value of name is not changed.
This function makes copies of the strings pointed to by name and value
(by contrast with putenv(3)).
The unsetenv() function deletes the variable name from the environment.
If name does not exist in the environment, then the function succeeds,
and the environment is unchanged.
RETURN VALUE
The setenv() function returns zero on success, or -1 if there was
insufficient space in the environment.
The unsetenv() function returns zero on success, or -1 on error, with
errno set to indicate the cause of the error.
ERRORS
EINVAL name contained an '=' character.
CONFORMING TO
4.3BSD, POSIX.1-2001.
NOTES
POSIX.1-2001 does not require setenv() or unsetenv() to be reentrant.
Prior to glibc 2.2.2, unsetenv() was prototyped as returning void; more
recent glibc versions follow the POSIX.1-2001-compliant prototype shown
in the SYNOPSIS.
BUGS
POSIX.1-2001 specifies that if name contains an '=' character, then
setenv() should fail with the error EINVAL; however, versions of glibc
before 2.3.4 allowed an '=' sign in name.
SEE ALSO
clearenv(3), getenv(3), putenv(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 SETENV(3)