#include <stdlib.h> int clearenv(void);
glibc 向けの機能検査マクロの要件 (feature_test_macros(7) 参照):
clearenv():
/* glibc >= 2.19: */ _DEFAULT_SOURCE
|| /* glibc <= 2.19: */ _SVID_SOURCE || _BSD_SOURCE
| インターフェース | 属性 | 値 |
| clearenv() | Thread safety | MT-Unsafe const:env |
(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() の追加は否決された。
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() はエラーを返し、プロセス環境は変更前のままにされる。