HPlogo MPE/iX Developer's Kit Reference Manual Volume I: HP 3000 MPE/iX Computer Systems > Chapter 4  POSIX/iX Library Function Descriptions

getenv

» 

Technical documentation

Complete book in PDF
» Feedback

 » Table of Contents

 » Index

Returns an environment value.

Syntax

   #include <stdlib.h>

   char *getenv (const char *name);

Parameters

name

A pointer to a string of characters to match in the environment list.

Return Values

<>NULL

A pointer to the value portion of a name=value string is returned.

NULL

A matching name was not found, and errno is not modified.

NULL + errno

An error occurred, and errno is set to indicate the error condition.

Description

The getenv() function takes a string, name, and searches for a matching name in the environment list (in environ) associated with the calling process.

If a match to name is found, getenv() returns a pointer to the value portion of that string. The value is terminated by a null character. If a matching name is not found, getenv() returns a NULL pointer but does not modify the current value of errno.

The environment list contains strings in the form name=value. If more than one string has the same name, getenv() returns the value for the first matching name found. The length of name is limited by {ARG_MAX} as defined in <limits.h>.

Implementation Considerations

Refer to the EFAULT error description below.

Errors

If an error occurs, errno is set to the following value:

EFAULTCAUSEThe system detected a NULL or bad address in attempting to use the name parameter or while dereferencing environ and traversing the process's environment list.
 ACTIONCheck to see if the pointer is correctly initialized or if the environment list is corrupted.

See Also

environ(), POSIX.1 (Section 4.6.1)

Feedback to webmaster