mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibCore: Be more BSD-friendly in Core::Environment
FreeBSD and NetBSD don't have secure_getenv(3), same as macOS. FreeBSD 13 and lower also don't allow setting environ pointers to null. Co-Authored-By: Robert Clausecker <fuz@FreeBSD.org>
This commit is contained in:
parent
89092e98a4
commit
405ce6e5f5
Notes:
sideshowbarker
2024-07-17 02:08:15 +09:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/405ce6e5f5 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/82
1 changed files with 8 additions and 5 deletions
|
@ -13,7 +13,7 @@
|
|||
#if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
|
||||
# include <crt_externs.h>
|
||||
#else
|
||||
extern char** environ;
|
||||
extern "C" char** environ;
|
||||
#endif
|
||||
|
||||
namespace Core::Environment {
|
||||
|
@ -93,15 +93,16 @@ Optional<StringView> get(StringView name, [[maybe_unused]] SecureOnly secure)
|
|||
builder.append('\0');
|
||||
// Note the explicit null terminators above.
|
||||
|
||||
#if defined(AK_OS_MACOS) || defined(AK_OS_ANDROID)
|
||||
char* result = ::getenv(builder.string_view().characters_without_null_termination());
|
||||
#else
|
||||
// FreeBSD < 14, Android, and generic BSDs do not support secure_getenv.
|
||||
#if (defined(__FreeBSD__) && __FreeBSD__ >= 14) || (!defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_ANDROID))
|
||||
char* result;
|
||||
if (secure == SecureOnly::Yes) {
|
||||
result = ::secure_getenv(builder.string_view().characters_without_null_termination());
|
||||
} else {
|
||||
result = ::getenv(builder.string_view().characters_without_null_termination());
|
||||
}
|
||||
#else
|
||||
char* result = ::getenv(builder.string_view().characters_without_null_termination());
|
||||
#endif
|
||||
if (result)
|
||||
return StringView { result, strlen(result) };
|
||||
|
@ -153,7 +154,9 @@ ErrorOr<void> put(StringView env)
|
|||
|
||||
ErrorOr<void> clear()
|
||||
{
|
||||
#if defined(AK_OS_MACOS)
|
||||
#if (defined(__FreeBSD__) && __FreeBSD__ < 14)
|
||||
environ = nullptr;
|
||||
#elif defined(AK_OS_BSD_GENERIC) && !defined(AK_OS_FREEBSD)
|
||||
auto environment = raw_environ();
|
||||
for (size_t environ_size = 0; environment[environ_size]; ++environ_size) {
|
||||
environment[environ_size] = NULL;
|
||||
|
|
Loading…
Reference in a new issue