putenv

Adds an environment variable or changes the value of an existing environment variable.

Library:LibC
Classification:ANSI
Service:Environment Variable

Syntax

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

Parameters

string

(IN) Points to a string that contains the name of an environment variable and its value in the form:

     "name=value"
  

The “name” is composed of characters in 7-bit ASCII and can be up to ENV_NAME_MAX (80) characters in length. The name is followed by an equal sign (0x3D), and it is followed by “value,” which is an ASCIIZ string.

A string without a value ("name=") is the same as calling the unsetenv function for that environment variable.

Return Values

If successful, returns 0. Otherwise, returns a nonzero value and sets errno to the following:

Decimal

Constant

Description

5

ENOMEM

Insufficient memory to add the variable or its value to the environment.

65

ENAMETOOLONG

The name for the environment variable is too long.

77

ESRCH

The environment variable was not found.

105

ENOCONTEXT

No thread context is present.

Remarks

The putenv function makes the value of the environment variable equal to value by altering an existing variable or creating a new one.

See Also