Skip to content

Commit c5bd21b

Browse files
committed
fix win build
1 parent a1aa99f commit c5bd21b

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

libs/cmdr11/include/cmdr11/cmdr_chrono.hh

+9-1
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,16 @@ namespace cmdr::chrono {
765765
std::tm *tm;
766766
if (iom_::has(iom_::fmtflags::gmt_or_local))
767767
tm = std::gmtime(&tt); // GMT (UTC)
768-
else // if (iom_::has(iom_::fmtflags::local))
768+
else { // if (iom_::has(iom_::fmtflags::local))
769+
#if defined(_WIN32) || defined(_WIN64)
770+
std::tm tm1;
771+
time_t now = time_t{0};
772+
localtime_s(&tm1, &now);
773+
tm = &tm1;
774+
#else
769775
tm = std::localtime(&tt); // Locale time-zone, usually UTC by default.
776+
#endif
777+
}
770778
// else
771779
// tm = std::gmtime(&tt); //GMT (UTC)
772780

libs/cmdr11/include/cmdr11/cmdr_common.hh

+12
Original file line numberDiff line numberDiff line change
@@ -1219,11 +1219,23 @@ namespace cmdr::util {
12191219
namespace cmdr::util {
12201220

12211221
inline std::string detect_shell_env() {
1222+
#if defined(_WIN32) || defined(_WIN64)
1223+
char* buf = nullptr;
1224+
size_t sz = 0;
1225+
if (_dupenv_s(&buf, &sz, "SHELL") == 0 && buf != nullptr)
1226+
{
1227+
auto path = std::filesystem::path(buf);
1228+
auto ret = path.filename().string();
1229+
free(buf);
1230+
return ret;
1231+
}
1232+
#else
12221233
auto *str = std::getenv("SHELL");
12231234
if (str != nullptr) {
12241235
auto path = std::filesystem::path(str);
12251236
return path.filename().string();
12261237
}
1238+
#endif
12271239
return "unknown";
12281240
}
12291241

libs/cmdr11/include/cmdr11/cmdr_string.hh

+10
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,18 @@ namespace cmdr::string {
510510
auto const &from = match[0];
511511
auto const &th = match[1];
512512
auto const &var_name = th.str();
513+
#if defined(_WIN32) || defined(_WIN64)
514+
char* buf = nullptr;
515+
size_t sz = 0;
516+
if (_dupenv_s(&buf, &sz, var_name.c_str()) == 0 && buf != nullptr)
517+
{
518+
text.replace(from.first, from.second, buf);
519+
free(buf);
520+
}
521+
#else
513522
auto *ptr = std::getenv(var_name.c_str());
514523
text.replace(from.first, from.second, ptr ? ptr : "");
524+
#endif
515525
}
516526
return text;
517527
}

0 commit comments

Comments
 (0)