Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ putenv(3) — CLIX 3.1r7.6.22

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

exec(2)

getenv(3)

malloc(3)

environ(4)



  putenv(3)                           CLIX                           putenv(3)



  NAME

    putenv - Changes or adds a value to the environment

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    int putenv(
      char *string );

  PARAMETERS

    string   Points to a string of the form name=value.  This string must be
             NULL terminated, where name is the name of the environment
             variable to be defined and value is the value to be assigned to
             this environment variable.

  DESCRIPTION

    The string parameter points 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().

  EXAMPLES

    This example sets the SHELL environment variable to the Korn shell.

    putenv("SHELL=/bin/ksh");


  NOTES

    The putenv() function manipulates the environment pointed to by environ(),
    and can be used in conjunction with getenv().  However, envp, the third
    argument to main, is not changed.

    This function uses malloc() to enlarge the environment.

  CAUTIONS

    After putenv() is called, environmental variables are not in alphabetical
    order.

    A potential error is to call putenv() with an automatic variable as the



  2/94 - Intergraph Corporation                                              1






  putenv(3)                           CLIX                           putenv(3)



    argument, then exit the calling function while string is still part of the
    environment.

  RETURN VALUES

    If no errors occur, putenv() returns a value of 0; otherwise, a value of 1
    is returned.  (Usually, the function could not obtain enough space with
    malloc() for the expanded environment.)

  RELATED INFORMATION

    Functions:  exec(2), getenv(3), malloc(3)

    Miscellany:  environ(4)








































  2                                              Intergraph Corporation - 2/94




Typewritten Software • bear@typewritten.org • Edmonds, WA 98026