diff --git a/Userland/Libraries/LibCore/Environment.cpp b/Userland/Libraries/LibCore/Environment.cpp index aa0952cb190..f0fc06a8845 100644 --- a/Userland/Libraries/LibCore/Environment.cpp +++ b/Userland/Libraries/LibCore/Environment.cpp @@ -13,7 +13,7 @@ #if defined(AK_OS_MACOS) || defined(AK_OS_IOS) # include #else -extern char** environ; +extern "C" char** environ; #endif namespace Core::Environment { @@ -93,15 +93,16 @@ Optional 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 put(StringView env) ErrorOr 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;