From HI-TECH C for CP/M Fan WIKI(EN)
Jump to: navigation, search



#include  <stdlib.h>

char *    getenv(char * s)
extern char **  environ;


Getenv() will search the vector of environment strings for one matching the argument supplied, and return the value part of that environment string. For example, if the environment contains the string


then getenv("COMSPEC") will return A:\COMMAND.COM. The global variable environ is a pointer to an array of pointers to environment strings, terminated by a null pointer. This array is initialized at startup time under MS-DOS from the environment pointer supplied when the program was executed. Under CP/M no such environment is supplied, so the first call to getenv() will attempt to open a file in the current user number on the current drive called ENVIRON. This file should contain definitions for any environment variables desired to be accessible to the program, e.g.


Each variable definition should be on a separate line, consisting of the variable name (conventionally all in upper case) followed without intervening white space by an equal sign ('=') then the value to be assigned to that variable.