clearenv

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

clearenv - 環境 (environment) をクリアする  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <stdlib.h>

int clearenv(void);

glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):

clearenv():

    /* glibc >= 2.19: */ _DEFAULT_SOURCE
        || /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
 

説明

The clearenv() function clears the environment of all name-value pairs and sets the value of the external variable environ to NULL. After this call, new variables can be added to the environment using putenv(3) and setenv(3).  

返り値

clearenv() 関数は、成功した場合は 0 を返し、 失敗した場合は 0 以外を返す。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
clearenv() Thread safetyMT-Unsafe const:env
 

標準規格

putenv()
POSIX.1-2008.
clearenv()
なし。
 

歴史

putenv()
glibc 2.0. POSIX.1-2001.
clearenv()
glibc 2.0.

(DG/UX, HP-UX, QNX, などの) 多くの UNIX 系 OS。 (FORTRAN77 へのバインディングである) POSIX.9。 POSIX.1-1996 では clearenv() と putenv(3) は採用されなかったが、 方針が変更され、この標準規格の以降の号 (§ B.4.6.1 を参照) では 採用されることになった。 しかし POSIX.1-2001 では putenv(3) だけが追加され、 clearenv() の追加は否決された。  

注意

On systems where clearenv() is unavailable, the assignment

environ = NULL;

というように変数 environ を設定すればよい。

The clearenv() function may be useful in security-conscious applications that want to precisely control the environment that is passed to programs executed using exec(3). The application would do this by first clearing the environment and then adding select environment variables.

Note that the main effect of clearenv() is to adjust the value of the pointer environ(7); this function does not erase the contents of the buffers containing the environment definitions.

DG/UX と Tru64 man ページには次のように記されている: environ が putenv(3), getenv(3), clearenv() 関数以外で変更された場合、 clearenv() はエラーを返し、プロセス環境は変更前のままにされる。  

関連項目

getenv(3), putenv(3), setenv(3), unsetenv(3), environ(7)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
注意
関連項目

This document was created by man2html, using the manual pages.