mescc: Mes C Library: Prepare for M2-Planet: setenv.

* lib/posix/setenv.c: Rewrite C-constructs not supported by M2-Planet.
This commit is contained in:
Jan Nieuwenhuizen 2019-10-20 19:28:58 +02:00
parent c01fb5aa4a
commit 998a3fdc15
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
1 changed files with 13 additions and 8 deletions

View File

@ -27,20 +27,25 @@ setenv (char const *s, char const *v, int overwrite_p)
{
char **p = environ;
int length = strlen (s);
while (*p)
while (p[0])
{
if (!strncmp (s, *p, length) && *(*p + length) == '=')
break;
p++;
if (strncmp (s, p[0], length) == 0)
{
char *q = p[0] + length;
if (q[0] == '=')
break;
}
p = p + 1;
}
char *entry = malloc (length + strlen (v) + 2);
int end_p = *p == 0;
*p = entry;
int end_p = p[0] == 0;
p[0] = entry;
strcpy (entry, s);
strcpy (entry + length, "=");
strcpy (entry + length + 1, v);
*(entry + length + strlen (v) + 2) = 0;
entry[length + strlen (v) + 2] = 0;
if (end_p)
*++p = 0;
p[1] = 0;
return 0;
}