1989-05-16 13:13:53 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-05-16 13:13:53 +00:00
|
|
|
|
2007-04-21 23:18:14 +00:00
|
|
|
#include <stdlib.h>
|
2013-05-29 20:41:58 +00:00
|
|
|
#include <string.h>
|
1989-05-16 13:13:53 +00:00
|
|
|
|
2013-05-29 20:41:58 +00:00
|
|
|
extern char* _findenv(const char* name, int* offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getenv(name) --
|
|
|
|
* Returns ptr to value associated with name, if any, else NULL.
|
|
|
|
*/
|
|
|
|
char* getenv(const char* name)
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
return(_findenv(name,&offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _findenv(name,offset) --
|
|
|
|
* Returns pointer to value associated with name, if any, else NULL.
|
|
|
|
* Sets offset to be the offset of the name/value combination in the
|
|
|
|
* environmental array, for use by setenv(3) and unsetenv(3).
|
|
|
|
* Explicitly removes '=' in argument name.
|
|
|
|
*
|
|
|
|
* This routine *should* be a static; don't use it.
|
|
|
|
*/
|
|
|
|
char* _findenv(register const char* name, int* offset)
|
1989-05-16 13:13:53 +00:00
|
|
|
{
|
2013-05-29 20:41:58 +00:00
|
|
|
extern char **environ;
|
|
|
|
register int len;
|
|
|
|
register char **P;
|
|
|
|
register const char *C;
|
|
|
|
|
|
|
|
if (!environ)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (C = name,len = 0;*C && *C != '=';++C,++len);
|
|
|
|
for (P = environ;*P;++P)
|
|
|
|
if (!strncmp(*P,name,len))
|
|
|
|
if (*(C = *P + len) == '=') {
|
|
|
|
*offset = P - environ;
|
|
|
|
return (char*)(++C);
|
|
|
|
}
|
|
|
|
return(NULL);
|
1989-05-16 13:13:53 +00:00
|
|
|
}
|
2013-05-29 20:41:58 +00:00
|
|
|
|