Borland C++ reference

putenv

raw OCR

Adds string to current environment.

Defined in header <stdlib.h>

Syntax

#include <stdhb.h>
int putenv(const char *name);

Portability

DOSUNIXWindowsANSI CC++ only
■■■

Remarks

putenv accepts the string name and adds it to the environment of the current process. For example,

putenv("PATH=C:\\BC"); putenv can also be used to modify or delete an existing name. You can set a variable to an empty value by specifying an empty string.

putenv can be used only to modify the current program's environment. Once the program ends, the old environment is restored.

Note that the string given to putenv must be static or global. Unpre-dictable results will occur if a local or dynamic string given to putenv is used after the string memory is released.

Return value

On success, putenv returns 0; on failure, -1.

See also

Example

#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <string.h>
#include <dos.h>

int main (void)
{
   char *path, *ptr;
   int i = 0;

   /* Get the current path  environment. */
   ptr = getenv ("PATH");
   /* set up new path  */
   path =  (char *) malloc(strlen(ptr)+15);
   Stropy (path,"PATH=");
   strcat(path,ptr) ;
   strcat (path, ";c:Wtemp") ;
   /* replace the current path  and display current environment
   putenv(path);
   while (environ[i])
       printf ("%s\n",environ[i++]);
   return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • header `stdhb.h` read as `stdlib.h`