Date: Mon, 14 May 2001 09:59:25 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Rafal Maj cc: djgpp AT delorie DOT com Subject: Re: getenv() question In-Reply-To: <9dnc8b$agu$1@info.cyf-kr.edu.pl> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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 #include 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; }