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:
Jan Nieuwenhuizen 2019-10-20 19:28:51 +02:00
parent 75895950fb
commit d454fe905d
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 19 additions and 5 deletions

View File

@ -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;
} }