Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <process.h>
    int putenv( const char *env_name );

Description:
    The environment list consists of a number of environment names, each of
    which has a value associated with it.  Entries can be added to the
    environment list with the DOS set command or with the putenv function.
     All entries in the environment list can be displayed by using the DOS
    set command with no arguments.  A program can obtain the value for an
    environment variable by using the  getenv function.

    When the value of env_name has the format


             env_name=value

    an environment name and its value is added to the environment list.
     When the value of env_name has the format


             env_name=

    the environment name and value is removed from the environment list.

    The matching is case-insensitive; all lowercase letters are treated as
    if they were in upper case.

    The space into which environment names and their values are placed is
    limited.  Consequently, the putenv function can fail when there is
    insufficient space remaining to store an additional value.

    NOTE:  If the argument env_name is not a literal string, you should
    duplicate the string, since putenv does not copy the value; for example,


             putenv( strdup( buffer ) );

    To assign a string to a variable and place it in the environment list:


             C>SET INCLUDE=C:\WATCOM\H

    To see what variables are in the environment list, and their current
    assignments:


             C>SET
             COMSPEC=C:\COMMAND.COM
             PATH=C:\;C:\WATCOM
             INCLUDE=C:\WATCOM\H

             C>


Returns:
    The putenv function returns zero when it is successfully executed and
    returns -1 when it fails.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    ENOMEM
        Not enough memory to allocate a new environment string.


See Also:
    clearenv, getenv, setenv

Example:
    The following gets the string currently assigned to  INCLUDE and
    displays it, assigns a new value to it, gets and displays it, and then
    removes the environment name and value.

    #include <stdio.h>
    #include <stdlib.h>

    void main()
      {
        char *path;
        path = getenv( "INCLUDE" );
        if( path != NULL )
            printf( "INCLUDE=%s\n", path );
        if( putenv( "INCLUDE=mylib;yourlib" ) != 0 )
            printf( "putenv failed" );
        path = getenv( "INCLUDE" );
        if( path != NULL )
            printf( "INCLUDE=%s\n", path );
        if( putenv( "INCLUDE=" ) != 0 )
            printf( "putenv failed" );
      }

    produces the following:

    INCLUDE=C:\WATCOM\H
    INCLUDE=mylib;yourlib

Classification:
    WATCOM

Systems:
    All

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson