summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore/System.cpp
diff options
context:
space:
mode:
authorLucas CHOLLET <lucas.chollet@free.fr>2022-03-01 23:43:55 +0100
committerAndreas Kling <kling@serenityos.org>2022-03-02 18:08:05 +0100
commitddf9987c39a6fcbd948461417cbb73004f88a1b0 (patch)
tree4365bfa80ad986b42874cd47b666c7d4cc47d1e8 /Userland/Libraries/LibCore/System.cpp
parentb1af1b399e5b6289e535b7ba64401a8c7590f11a (diff)
downloadserenity-ddf9987c39a6fcbd948461417cbb73004f88a1b0.zip
LibCore+LibC: Add wrapper for setenv
I also added a common interface with StringView compatible parameters: int serenity_setenv(const char*, ssize_t, const char*, ssize_t, int) This function is called by both C and C++ API for setenv().
Diffstat (limited to 'Userland/Libraries/LibCore/System.cpp')
-rw-r--r--Userland/Libraries/LibCore/System.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp
index 484ed5b878..ff29dc69c6 100644
--- a/Userland/Libraries/LibCore/System.cpp
+++ b/Userland/Libraries/LibCore/System.cpp
@@ -14,6 +14,7 @@
#include <LibSystem/syscall.h>
#include <limits.h>
#include <stdarg.h>
+#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/ptrace.h>
@@ -1069,4 +1070,18 @@ ErrorOr<void> mkfifo(StringView pathname, mode_t mode)
return mknod(pathname, mode | S_IFIFO, 0);
}
+ErrorOr<void> setenv(StringView name, StringView value, bool overwrite)
+{
+#ifdef __serenity__
+ auto const rc = ::serenity_setenv(name.characters_without_null_termination(), name.length(), value.characters_without_null_termination(), value.length(), overwrite);
+#else
+ String name_string = name;
+ String value_string = value;
+ auto const rc = ::setenv(name_string.characters(), value_string.characters(), overwrite);
+#endif
+ if (rc < 0)
+ return Error::from_syscall("setenv", -errno);
+ return {};
+}
+
}