[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1

getenv Subroutine

Purpose

Returns the value of an environment variable.

Library

Standard C Library (libc.a)

Syntax

#include <stdlib.h>


char *getenv ( Name)
const char *Name;

Description

The getenv subroutine searches the environment list for a string of the form Name=Value. Environment variables are sometimes called shell variables because they are frequently set with shell commands.

Parameters

Name Specifies the name of an environment variable. If a string of the proper form is not present in the current environment, the getenv subroutine returns a null pointer.

Return Values

The getenv subroutine returns a pointer to the value in the current environment, if such a string is present. If such a string is not present, a null pointer is returned. The getenv subroutine normally does not modify the returned string. The putenv subroutine, however, may overwrite or change the returned string. Do not attempt to free the returned pointer. The getenv subroutine returns a pointer to the user's copy of the environment (which is static), until the first invocation of the putenv subroutine that adds a new environment variable. The putenv subroutine allocates an area of memory large enough to hold both the user's environment and the new variable. The next call to the getenv subroutine returns a pointer to this newly allocated space that is not static. Subsequent calls by the putenv subroutine use the realloc subroutine to make space for new variables. Unsuccessful completion returns a null pointer.

Related Information

The putenv (putenv Subroutine) subroutine.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]