Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


putenv(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |ATTRIBUTES |STANDARDS |HISTORY |SEE ALSO |COLOPHON

putenv(3)                Library Functions Manualputenv(3)

NAME        top

       putenv - change or add an environment variable

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <stdlib.h>int putenv(char *string);   Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):putenv():           _XOPEN_SOURCE               || /* glibc >= 2.19: */ _DEFAULT_SOURCE               || /* glibc <= 2.19: */ _SVID_SOURCE

DESCRIPTION        top

       Theputenv() function adds or changes the value of environment       variables.  The argumentstring is of the formname=value.  Ifname does not already exist in the environment, thenstring is       added to the environment.  Ifname does exist, then the value ofname in the environment is changed tovalue.  The string pointed       to bystring becomes part of the environment, so altering the       string changes the environment.

RETURN VALUE        top

       Theputenv() function returns zero on success.  On failure, it       returns a nonzero value, anderrno is set to indicate the error.

ERRORS        top

ENOMEMInsufficient space to allocate new environment.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌──────────────────────────┬───────────────┬─────────────────────┐       │InterfaceAttributeValue│       ├──────────────────────────┼───────────────┼─────────────────────┤       │putenv()                 │ Thread safety │ MT-Unsafe const:env │       └──────────────────────────┴───────────────┴─────────────────────┘

STANDARDS        top

       POSIX.1-2008.

HISTORY        top

       POSIX.1-2001, SVr2, 4.3BSD-Reno.       Theputenv() function is not required to be reentrant, and the one       in glibc 2.0 is not, but the glibc 2.1 version is.       Since glibc 2.1.2, the glibc implementation conforms to SUSv2: the       pointerstring given toputenv() is used.  In particular, this       string becomes part of the environment; changing it later will       change the environment.  (Thus, it is an error to callputenv()       with an automatic variable as the argument, then return from the       calling function whilestring is still part of the environment.)       However, from glibc 2.0 to glibc 2.1.1, it 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.       The 4.3BSD-Reno version, like glibc 2.0, uses a copy; this is       fixed in all modern BSDs.       SUSv2 removes theconst from the prototype, and so does glibc       2.1.3.       The GNU C library implementation provides a nonstandard extension.       Ifstring does not include an equal sign:           putenv("NAME");       then the named variable is removed from the caller's environment.

SEE ALSO        top

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

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-17putenv(3)

Pages that refer to this page:clearenv(3)getenv(3)pam_putenv(3)setenv(3)proc_pid_environ(5)environ(7)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp