80 lines
1.9 KiB
C++
80 lines
1.9 KiB
C++
/***
|
|
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;
|
|
|
|
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;
|
|
}
|
|
|
|
AUKN_SYM AuOptional<AuString> EnvironmentGetOne(const AuString &key)
|
|
{
|
|
AU_LOCK_GUARD(gEnvMutex);
|
|
|
|
if (key.empty())
|
|
{
|
|
SysPushErrorArg("Missing key");
|
|
return {};
|
|
}
|
|
|
|
auto pValue = ::getenv(key.c_str());
|
|
return pValue ? AuString(pValue) : AuOptional<AuString> {};
|
|
}
|
|
|
|
AUKN_SYM bool EnvironmentSetOne(const AuString &key, const AuString &value)
|
|
{
|
|
AU_LOCK_GUARD(gEnvMutex);
|
|
|
|
if (key.empty())
|
|
{
|
|
SysPushErrorArg("Missing key");
|
|
return false;
|
|
}
|
|
|
|
if (value.empty())
|
|
{
|
|
SysPushErrorArg("Missing value");
|
|
return false;
|
|
}
|
|
|
|
return ::setenv(key.c_str(), value.c_str(), 1) == 0;
|
|
}
|
|
|
|
AUKN_SYM bool EnvironmentRemoveOne(const AuString &key)
|
|
{
|
|
AU_LOCK_GUARD(gEnvMutex);
|
|
|
|
if (key.empty())
|
|
{
|
|
SysPushErrorArg("Missing key");
|
|
return false;
|
|
}
|
|
|
|
return ::unsetenv(key.c_str()) == 0;
|
|
}
|
|
} |