1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 09:37:44 +00:00

LibCore+LibC: Add putenv() wrapper

This is made safe with a special serenity_putenv() function in LibC.
This commit is contained in:
MacDue 2023-02-04 15:44:33 +00:00 committed by Andreas Kling
parent f4236e61bf
commit eea4dc5bfe
4 changed files with 24 additions and 0 deletions

View file

@ -1442,6 +1442,20 @@ ErrorOr<void> setenv(StringView name, StringView value, bool overwrite)
return {};
}
ErrorOr<void> putenv(StringView env)
{
#ifdef AK_OS_SERENITY
auto rc = serenity_putenv(env.characters_without_null_termination(), env.length());
#else
// Leak somewhat unavoidable here due to the putenv API.
auto leaked_new_env = strndup(env.characters_without_null_termination(), env.length());
auto rc = ::putenv(leaked_new_env);
#endif
if (rc < 0)
return Error::from_errno(errno);
return {};
}
ErrorOr<int> posix_openpt(int flags)
{
int const rc = ::posix_openpt(flags);