Skip to content

Commit

Permalink
Implement Environment::list method for Linux.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Chapyshev committed Jul 7, 2023
1 parent d5bdd53 commit 6d4c00a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion source/base/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "base/strings/unicode.h"
#include "build/build_config.h"

#include <cstring>
#include <memory>
#include <vector>

Expand All @@ -31,6 +32,10 @@
#include <stdlib.h>
#endif

#if defined(OS_LINUX)
extern char** environ;
#endif

namespace base {

namespace {
Expand Down Expand Up @@ -164,7 +169,18 @@ std::vector<std::pair<std::string, std::string>> Environment::list()

FreeEnvironmentStringsW(strings);
return result;

#elif defined(OS_LINUX)
for (char** current = environ; *current; current++)
{
char* name = strtok(*current, "=");
if (name)
{
char* value = strtok(nullptr, "=");
if (value)
result.emplace_back(name, value);
}
}
return result;
#else
return result;
#endif
Expand Down

0 comments on commit 6d4c00a

Please sign in to comment.