m2: getenv

This commit is contained in:
Jan Nieuwenhuizen 2019-10-24 07:19:57 +02:00
parent 99c1d3df1c
commit fcb694be6b
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 7 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* -*-comment-start: "//";comment-end:""-*-
/* -*-comment-start: "
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
@ -25,18 +25,22 @@
char *
getenv (char *s)
{
/* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */
char **p = environ;
int length = strlen (s);
while (p[0] != 0)
{
/* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */
if (strncmp (s, p[0], length) == 0)
{
/* eputs ("found!\n"); */
char *q = p[0] + length;
if (q[0] == '=')
return q + 1;
}
p = p + 1;
/* else */
/* eputs ("not found!\n"); */
p = p + sizeof (char *); /* FIXME! */
}
return 0;