mescc: Mes C Library: Prepare for M2-Planet: getenv.
* lib/posix/getenv.c: Rewrite C-constructs not supported by M2-Planet.
This commit is contained in:
parent
d49ea35044
commit
cf7fc8ec2b
|
@ -1,4 +1,4 @@
|
||||||
/* -*-comment-start: "//";comment-end:""-*-
|
/*
|
||||||
* GNU Mes --- Maxwell Equations of Software
|
* GNU Mes --- Maxwell Equations of Software
|
||||||
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
* Copyright © 2016,2017,2018,2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
||||||
*
|
*
|
||||||
|
@ -22,16 +22,30 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
// CONSTANT M2_PTR_SIZE 4
|
||||||
|
#define M2_PTR_SIZE 1
|
||||||
|
|
||||||
char *
|
char *
|
||||||
getenv (char const *s)
|
getenv (char const *s)
|
||||||
{
|
{
|
||||||
|
/* eputs ("\ngetenv s="); eputs (s); eputs ("\n"); */
|
||||||
char **p = environ;
|
char **p = environ;
|
||||||
int length = strlen (s);
|
int length = strlen (s);
|
||||||
while (*p)
|
|
||||||
|
while (p[0] != 0)
|
||||||
{
|
{
|
||||||
if (!strncmp (s, *p, length) && *(*p + length) == '=')
|
/* eputs ("getenv p[0]="); eputs (p[0]); eputs ("\n"); */
|
||||||
return (*p + length + 1);
|
if (strncmp (s, p[0], length) == 0)
|
||||||
p++;
|
{
|
||||||
|
/* eputs ("found!\n"); */
|
||||||
|
char *q = p[0] + length;
|
||||||
|
if (q[0] == '=')
|
||||||
|
return q + 1;
|
||||||
}
|
}
|
||||||
|
/* else */
|
||||||
|
/* eputs ("not found!\n"); */
|
||||||
|
p = p + M2_PTR_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue