mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +00:00
LibCore+LibC: Add putenv() wrapper
This is made safe with a special serenity_putenv() function in LibC.
This commit is contained in:
parent
f4236e61bf
commit
eea4dc5bfe
4 changed files with 24 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue