Scroll to navigation

putenv(3) Library Functions Manual putenv(3)

NOM

putenv - Ajouter ou modifier une variable d'environnement

BIBLIOTHÈQUE

Bibliothèque C standard (libc, -lc)

SYNOPSIS

#include <stdlib.h>
int putenv(char *string);

Exigences de macros de test de fonctionnalités pour la glibc (consulter feature_test_macros(7)) :

putenv() :


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

DESCRIPTION

La fonction putenv() ajoute ou modifie la valeur d'une variable d'environnement. L'argument string est une chaîne de caractères de la forme nom=valeur. Si nom n'existe pas dans l'environnement, string est ajoutée. Si nom existe, alors la valeur de de nom est remplacée par valeur. La chaîne pointée par string devient partie intégrante de l'environnement, ainsi une modification de cette chaîne change l'environnement.

VALEUR RENVOYÉE

La fonction putenv() renvoie 0 si elle réussit. En cas d'erreur, une valeur non nulle est renvoyée et errno contient le code d'erreur.

ERREURS

Pas assez de mémoire.

ATTRIBUTS

Pour une explication des termes utilisés dans cette section, consulter attributes(7).

Interface Attribut Valeur
putenv() Sécurité des threads MT-Unsafe const:env

STANDARDS

POSIX.1-2008.

HISTORIQUE

POSIX.1-2001, SVr2, 4.3BSD-Reno.

La fonction putenv() n'a pas besoin d'être réentrante, celle de la glibc 2.0 ne l'est pas, contrairement à celle de la glibc 2.1.

Since glibc 2.1.2, the glibc implementation conforms 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 to call putenv() with an automatic variable as the argument, then return from the calling function while string 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.

Dans les spécifications SUSv2, le const a été supprimé du prototype. C'est aussi le cas dans glibc 2.1.3.

L'implémentation de la bibliothèque C GNU fournit une extension non standard. Si string ne comporte pas de signe égal :


putenv("NAME");

alors la variable nommée est supprimée de l'environnement de l'appelant.

VOIR AUSSI

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

TRADUCTION

La traduction française de cette page de manuel a été créée par Christophe Blaess <https://www.blaess.fr/christophe/>, Stéphan Rafin <stephan.rafin@laposte.net>, Thierry Vignaud <tvignaud@mandriva.com>, François Micaux, Alain Portal <aportal@univ-montp2.fr>, Jean-Philippe Guérard <fevrier@tigreraye.org>, Jean-Luc Coulon (f5ibh) <jean-luc.coulon@wanadoo.fr>, Julien Cristau <jcristau@debian.org>, Thomas Huriaux <thomas.huriaux@gmail.com>, Nicolas François <nicolas.francois@centraliens.net>, Florentin Duneau <fduneau@gmail.com>, Simon Paillard <simon.paillard@resel.enst-bretagne.fr>, Denis Barbier <barbier@debian.org>, David Prévot <david@tilapin.org> et Grégoire Scano <gregoire.scano@malloc.fr>

Cette traduction est une documentation libre ; veuillez vous reporter à la GNU General Public License version 3 concernant les conditions de copie et de distribution. Il n'y a aucune RESPONSABILITÉ LÉGALE.

Si vous découvrez un bogue dans la traduction de cette page de manuel, veuillez envoyer un message à debian-l10n-french@lists.debian.org.

20 juillet 2023 Pages du manuel de Linux 6.05.01