m2: getenv
This commit is contained in:
parent
99c1d3df1c
commit
fcb694be6b
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue