2023-07-10 15:29:38 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: AuProcessEnvironment.Unix.cpp
|
|
|
|
Date: 2023-7-10
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "AuProcessEnvironment.hpp"
|
|
|
|
#include "AuProcessEnvironment.Unix.hpp"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
namespace Aurora::Process
|
|
|
|
{
|
|
|
|
static AuThreadPrimitives::Mutex gEnvMutex;
|
|
|
|
|
2024-01-21 18:41:53 +00:00
|
|
|
void PosixForkResetLocks()
|
|
|
|
{
|
|
|
|
AuResetMember(gEnvMutex);
|
|
|
|
}
|
|
|
|
|
2023-07-10 15:29:38 +00:00
|
|
|
AUKN_SYM AuList<AuPair<AuString, AuString>> EnvironmentGetAll()
|
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(gEnvMutex);
|
|
|
|
AuList<AuPair<AuString, AuString>> ret;
|
|
|
|
|
|
|
|
auto pIterator = environ;
|
|
|
|
while (auto pCurrent = *(pIterator++))
|
|
|
|
{
|
|
|
|
auto optSplit = EnvironmentSplitString(pCurrent);
|
|
|
|
if (optSplit)
|
|
|
|
{
|
|
|
|
ret.push_back(optSplit.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-04-28 12:22:47 +00:00
|
|
|
AUKN_SYM AuOptional<AuString> EnvironmentGetOne(const AuRONString &key)
|
2023-07-10 15:29:38 +00:00
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(gEnvMutex);
|
|
|
|
|
|
|
|
if (key.empty())
|
|
|
|
{
|
2023-07-10 19:56:45 +00:00
|
|
|
SysPushErrorArg("Missing key");
|
2023-08-11 15:51:42 +00:00
|
|
|
return {};
|
2023-07-10 15:29:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto pValue = ::getenv(key.c_str());
|
|
|
|
return pValue ? AuString(pValue) : AuOptional<AuString> {};
|
|
|
|
}
|
|
|
|
|
2024-04-28 12:22:47 +00:00
|
|
|
AUKN_SYM bool EnvironmentSetOne(const AuRONString &key, const AuRONString &value)
|
2023-07-10 15:29:38 +00:00
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(gEnvMutex);
|
2023-07-10 19:56:45 +00:00
|
|
|
|
2023-07-10 15:29:38 +00:00
|
|
|
if (key.empty())
|
|
|
|
{
|
2023-07-10 19:56:45 +00:00
|
|
|
SysPushErrorArg("Missing key");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-28 12:22:47 +00:00
|
|
|
#if 0
|
2023-07-10 19:56:45 +00:00
|
|
|
if (value.empty())
|
|
|
|
{
|
|
|
|
SysPushErrorArg("Missing value");
|
2023-07-10 15:29:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
2024-04-28 12:22:47 +00:00
|
|
|
#endif
|
2023-07-10 15:29:38 +00:00
|
|
|
|
|
|
|
return ::setenv(key.c_str(), value.c_str(), 1) == 0;
|
|
|
|
}
|
|
|
|
|
2024-04-28 12:22:47 +00:00
|
|
|
AUKN_SYM bool EnvironmentRemoveOne(const AuRONString &key)
|
2023-07-10 15:29:38 +00:00
|
|
|
{
|
|
|
|
AU_LOCK_GUARD(gEnvMutex);
|
|
|
|
|
|
|
|
if (key.empty())
|
|
|
|
{
|
2023-07-10 19:56:45 +00:00
|
|
|
SysPushErrorArg("Missing key");
|
2023-07-10 15:29:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ::unsetenv(key.c_str()) == 0;
|
|
|
|
}
|
|
|
|
}
|