From e87d78afa87cd031eeb07e2b0b2ec62bd04924af Mon Sep 17 00:00:00 2001 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 1 Nov 2022 21:53:33 +0100 Subject: [PATCH] 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. --- build-aux/configure-lib.sh | 1 + include/stdlib.h | 1 + lib/posix/putenv.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 lib/posix/putenv.c diff --git a/build-aux/configure-lib.sh b/build-aux/configure-lib.sh index f1df1542..13b06083 100644 --- a/build-aux/configure-lib.sh +++ b/build-aux/configure-lib.sh @@ -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 diff --git a/include/stdlib.h b/include/stdlib.h index f388a194..fe9d574d 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -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); diff --git a/lib/posix/putenv.c b/lib/posix/putenv.c new file mode 100644 index 00000000..000c88ac --- /dev/null +++ b/lib/posix/putenv.c @@ -0,0 +1,35 @@ +/* -*-comment-start: "//";comment-end:""-*- + * GNU Mes --- Maxwell Equations of Software + * Copyright © 2022 Jan (janneke) Nieuwenhuizen + * + * 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 . + */ + +#include +#include +#include + +int +putenv (char *s) +{ + char *value = strchr (s, '='); + if (!value) + return unsetenv (s); + + *value++ = '0'; + value = ""; + return setenv (s, value, 1); +}