Commit a5a61149 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Implement clearenv in the portability headers

Summary:
It doesn't exist on OSX or Windows, so implement it.

Closes https://github.com/facebook/folly/issues/567

Reviewed By: yfeldblum

Differential Revision: D4783463

fbshipit-source-id: 0a2586aced7123b797a8e55a3e86124b449634e4
parent 1d11ad7a
......@@ -136,3 +136,30 @@ int unsetenv(const char* name) {
}
}
#endif
#if !__linux__ && !FOLLY_MOBILE
#include <string>
#include <vector>
extern "C" int clearenv() {
std::vector<std::string> data;
for (auto it = environ; it && *it; ++it) {
std::string entry(*it);
auto equalsPosition = entry.find('=');
if (equalsPosition == std::string::npos || equalsPosition == 0) {
// It's either a drive setting (if on Windows), or something clowny is
// going on in the environment.
continue;
} else {
data.emplace_back(entry.substr(0, equalsPosition));
}
}
for (auto s : data) {
if (unsetenv(s.c_str()) != 0)
return -1;
}
return 0;
}
#endif
......@@ -47,4 +47,8 @@ char*** _NSGetEnviron(void);
#endif
#define environ (*_NSGetEnviron())
#endif
#if !__linux__ && !FOLLY_MOBILE
int clearenv();
#endif
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment