30 char* mktemp(
char* tn) {
37 char* mkdtemp(
char* tn) {
39 auto len = strlen(tn);
42 strcpy(tn + len - 6,
"XXXXXX");
44 if (ptr ==
nullptr || *ptr ==
'\0') {
47 ret = mkdir(ptr, 0700);
48 if (ret != 0 && errno != EEXIST) {
55 int mkstemp(
char* tn) {
57 auto len = strlen(tn);
60 strcpy(tn + len - 6,
"XXXXXX");
62 if (ptr ==
nullptr || *ptr ==
'\0') {
65 ret = open(ptr, O_RDWR | O_EXCL | O_CREAT, S_IRUSR | S_IWUSR);
66 if (ret == -1 && errno != EEXIST) {
73 char* realpath(
const char* path,
char* resolved_path) {
75 return _fullpath(resolved_path, path, _MAX_PATH);
78 int setenv(
const char*
name,
const char*
value,
int overwrite) {
79 if (overwrite == 0 && getenv(name) !=
nullptr) {
84 auto e = _putenv_s(name, value);
96 if (_putenv_s(name,
" ") != 0) {
103 *getenv(name) =
'\0';
108 *(getenv(name) + 1) =
'=';
115 if (_wenviron !=
nullptr) {
116 wchar_t buf[_MAX_ENV + 1];
118 if (mbstowcs_s(&len, buf, _MAX_ENV + 1, name, _MAX_ENV) != 0) {
122 *_wgetenv(buf) = u
'\0';
123 *(_wgetenv(buf) + 1) = u
'=';
128 if (!SetEnvironmentVariableA(name, value)) {
135 int unsetenv(
const char* name) {
136 if (_putenv_s(name,
"") != 0) {
145 #if !__linux__ && !FOLLY_MOBILE 151 std::vector<std::string>
data;
152 for (
auto it =
environ; it && *it; ++it) {
154 auto equalsPosition = entry.find(
'=');
155 if (equalsPosition == std::string::npos || equalsPosition == 0) {
160 data.emplace_back(entry.substr(0, equalsPosition));
164 for (
auto s : data) {
165 if (unsetenv(
s.c_str()) != 0)
static const char *const value
static constexpr uint64_t data[1]