Mail Archives: djgpp/2001/05/14/02:59:56
On Mon, 14 May 2001, Rafal Maj wrote:
> how to check ammount of variables in environment, and get all of them ? Like
> getenv() but when I don't now environment variable name.
Use the `environ' array. It's NULL-terminated, like `argv', so you
can walk it with a simple loop.
As an example, here's the source of DJGPP's implementation of
`getenv':
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
extern char **environ;
char *
getenv(const char *name)
{
int i;
if (environ == 0)
return 0;
for (i=0; environ[i]; i++)
{
char *ep = environ[i];
const char *np = name;
while (*ep && *np && *ep == *np && *np != '=')
ep++, np++;
if (*ep == '=' && *np == 0)
return ep+1;
}
return 0;
}
- Raw text -