Skip to content

Commit 0876542

Browse files
committed
Fix getenv
1 parent b8c80a5 commit 0876542

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

modules/core/util/src/util.cpp

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
#include "core/util/include/util.hpp"
22

33
#include <cstdlib>
4-
#ifdef _WIN32
5-
#include <cstdint>
6-
#include <iostream>
7-
#include <memory>
8-
#include <vector>
9-
#endif
10-
114
#include <filesystem>
125
#include <string>
136

@@ -17,17 +10,13 @@ std::string ppc::util::GetAbsolutePath(const std::string &relative_path) {
1710
}
1811

1912
int ppc::util::GetPPCNumThreads() {
20-
#ifdef _WIN32
21-
size_t len;
22-
char omp_env[100];
23-
errno_t err = getenv_s(&len, omp_env, sizeof(omp_env), "PPC_NUM_THREADS");
24-
if (err != 0 || len == 0) {
25-
omp_env[0] = '\0';
13+
const char *env = std::getenv("PPC_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe)
14+
if ((env != nullptr) && (*env != 0)) {
15+
char *endptr = nullptr;
16+
long val = std::strtol(env, &endptr, 10);
17+
if (endptr != env && val > 0) {
18+
return static_cast<int>(val);
19+
}
2620
}
27-
int num_threads = std::atoi(omp_env);
28-
#else
29-
const char *omp_env = std::getenv("PPC_NUM_THREADS"); // NOLINT(concurrency-mt-unsafe)
30-
int num_threads = (omp_env != nullptr) ? std::atoi(omp_env) : 1;
31-
#endif
32-
return num_threads;
21+
return 1;
3322
}

0 commit comments

Comments
 (0)