DRAFT lib: Add putenv.

* lib/posix/putenv.c: New file.
* build-aux/configure-lib.sh (libc_gnu_SOURCES): Add it.
* include/stdlib.h (putenv): Add prototype.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2022-11-01 21:53:33 +01:00
parent d814b6dbed
commit 5281b8e611
No known key found for this signature in database
GPG Key ID: F3C1A0D9C1D65273
3 changed files with 37 additions and 0 deletions

View File

@ -331,6 +331,7 @@ lib/posix/alarm.c
lib/posix/execl.c
lib/posix/execlp.c
lib/posix/mktemp.c
lib/posix/putenv.c
lib/posix/sbrk.c
lib/posix/sleep.c
lib/posix/unsetenv.c

View File

@ -45,6 +45,7 @@ void _exit (int status);
void exit (int status);
void free (void *ptr);
char *getenv (char const *s);
int putenv (char *s);
int setenv (char const *s, char const *v, int overwrite_p);
int unsetenv (char const *name);
void *malloc (size_t);

35
lib/posix/putenv.c Normal file
View File

@ -0,0 +1,35 @@
/* -*-comment-start: "//";comment-end:""-*-
* GNU Mes --- Maxwell Equations of Software
* Copyright © 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
*
* This file is part of GNU Mes.
*
* GNU Mes is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* GNU Mes is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
*/
#include <mes/lib.h>
#include <string.h>
#include <stdlib.h>
int
putenv (char *s)
{
char *value = strchr (s, '=');
if (!value)
return unsetenv (s);
*value++ = '0';
value = "";
return setenv (s, value, 1);
}