$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/fdt))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/isrlib))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/nolibc))
+$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-environ))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-event))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-libdl))
$(eval $(call _import_lib,$(CONFIG_UK_BASE)/lib/posix-mmap))
void qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
+#if CONFIG_LIBPOSIX_ENVIRON
+int setenv(const char *name, const char *value, int overwrite);
+int unsetenv(const char *name);
+int clearenv(void);
+int putenv(char *string);
+char *getenv(const char *name);
+#endif /* CONFIG_LIBPOSIX_ENVIRON */
+
#if CONFIG_LIBPOSIX_PROCESS
int system(const char *command);
#endif
--- /dev/null
+config LIBPOSIX_ENVIRON
+ bool "posix-environ: Environment variables"
+ default n
+ select LIBNOLIBC if !HAVE_LIBC
--- /dev/null
+$(eval $(call addlib_s,libposix_environ,$(CONFIG_LIBPOSIX_ENVIRON)))
+
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/setenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/unsetenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/clearenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/putenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/getenv.c
+LIBPOSIX_ENVIRON_SRCS-y += $(LIBPOSIX_ENVIRON_BASE)/environ.c
#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
-
-static void dummy(char *old, char *new) {}
-weak_alias(dummy, __env_rm_add);
+#include "environ.h"
int clearenv()
{
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+#include <uk/essentials.h>
+#include "environ.h"
+
+char **__environ = __NULL;
--- /dev/null
+/* SPDX-License-Identifier: BSD-3-Clause */
+/* Copyright (c) 2023, Unikraft GmbH and The Unikraft Authors.
+ * Licensed under the BSD-3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ */
+#ifndef __ENVIRON_H__
+#define __ENVIRON_H__
+
+#include <uk/config.h>
+#include <stdlib.h>
+
+extern char **__environ;
+
+int __putenv(char *s, size_t l, char *r);
+void __env_rm_add(char *old, char *new);
+
+#endif /* __ENVIRON_H__ */
--- /dev/null
+setenv
+unsetenv
+clearenv
+putenv
+getenv
+__environ
* File: src/env/getenv.c
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include "environ.h"
char *getenv(const char *name)
{
- size_t l = __strchrnul(name, '=') - name;
+ size_t l = strchrnul(name, '=') - name;
if (l && !name[l] && __environ)
for (char **e = __environ; *e; e++)
if (!strncmp(name, *e, l) && l[*e] == '=')
* File: src/env/putenv.c
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-
-static void dummy(char *old, char *new) {}
-weak_alias(dummy, __env_rm_add);
+#include "environ.h"
int __putenv(char *s, size_t l, char *r)
{
int putenv(char *s)
{
- size_t l = __strchrnul(s, '=') - s;
+ size_t l = strchrnul(s, '=') - s;
if (!l || !s[l]) return unsetenv(s);
return __putenv(s, l, 0);
}
* File: src/env/setenv.c
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include "environ.h"
void __env_rm_add(char *old, char *new)
{
char *s;
size_t l1, l2;
- if (!var || !(l1 = __strchrnul(var, '=') - var) || var[l1]) {
+ if (!var || !(l1 = strchrnul(var, '=') - var) || var[l1]) {
errno = EINVAL;
return -1;
}
* File: src/env/unsetenv.c
*/
+#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
-
-static void dummy(char *old, char *new) {}
-weak_alias(dummy, __env_rm_add);
+#include "environ.h"
int unsetenv(const char *name)
{
- size_t l = __strchrnul(name, '=') - name;
+ size_t l = strchrnul(name, '=') - name;
if (!l || name[l]) {
errno = EINVAL;
return -1;