The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group

 NAME

putenv - change or add a value to environment

 SYNOPSIS



#include <stdlib.h>

int putenv(char *string);

 DESCRIPTION

The putenv() function uses the string argument to set environment variable values. The string argument should point to a string of the form "name=value". The putenv() function makes the value of the environment variable name equal to value by altering an existing variable or creating a new one. In either case, the string pointed to by string becomes part of the environment, so altering the string will change the environment. The space used by string is no longer used once a new string-defining name is passed to putenv().

This interface need not be reentrant.

 RETURN VALUE

Upon successful completion, putenv() returns 0. Otherwise, it returns a non-zero value and sets errno to indicate the error.

 ERRORS

The putenv() function may fail if:
[ENOMEM]
Insufficient memory was available.

 EXAMPLES

None.

 APPLICATION USAGE

The putenv() function manipulates the environment pointed to by environ, and can be used in conjunction with getenv().

This routine may use malloc() to enlarge the environment.

A potential error is to call putenv() with an automatic variable as the argument, then return from the calling function while string is still part of the environment.

 FUTURE DIRECTIONS

None.

 SEE ALSO

exec, getenv(), malloc(), <stdlib.h>.

DERIVATION

Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]