File tree 3 files changed +31
-1
lines changed
libs/cmdr11/include/cmdr11
3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -765,8 +765,16 @@ namespace cmdr::chrono {
765
765
std::tm *tm ;
766
766
if (iom_::has (iom_::fmtflags::gmt_or_local))
767
767
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
769
775
tm = std::localtime (&tt); // Locale time-zone, usually UTC by default.
776
+ #endif
777
+ }
770
778
// else
771
779
// tm = std::gmtime(&tt); //GMT (UTC)
772
780
Original file line number Diff line number Diff line change @@ -1219,11 +1219,23 @@ namespace cmdr::util {
1219
1219
namespace cmdr ::util {
1220
1220
1221
1221
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
1222
1233
auto *str = std::getenv (" SHELL" );
1223
1234
if (str != nullptr ) {
1224
1235
auto path = std::filesystem::path (str);
1225
1236
return path.filename ().string ();
1226
1237
}
1238
+ #endif
1227
1239
return " unknown" ;
1228
1240
}
1229
1241
Original file line number Diff line number Diff line change @@ -510,8 +510,18 @@ namespace cmdr::string {
510
510
auto const &from = match[0 ];
511
511
auto const &th = match[1 ];
512
512
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
513
522
auto *ptr = std::getenv (var_name.c_str ());
514
523
text.replace (from.first , from.second , ptr ? ptr : " " );
524
+ #endif
515
525
}
516
526
return text;
517
527
}
You can’t perform that action at this time.
0 commit comments