From b5ae2ddea373ea71e0574d7a14dd73ddf10bf8a2 Mon Sep 17 00:00:00 2001 From: "hyunghwan.chung" Date: Sat, 1 Dec 2018 13:44:57 +0000 Subject: [PATCH] changed to use sprintf() if strftime() doesn't work --- moo/lib/std.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/moo/lib/std.c b/moo/lib/std.c index f4d6dc7..db25b8d 100644 --- a/moo/lib/std.c +++ b/moo/lib/std.c @@ -872,21 +872,12 @@ static void log_write (moo_t* moo, moo_bitmask_t mask, const moo_ooch_t* msg, mo tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S %z ", tmp); if (tslen == 0) { - tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S ", tmp); - if (tslen == 0) - { - strcpy (ts, "0000-00-00 00:00:00 +0000 "); - tslen = 26; - } + tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); } #elif defined(__DOS__) tmp = localtime(&now); - tslen = strftime(ts, sizeof(ts), "%Y-%m-%d %H:%M:%S ", tmp); /* no timezone info */ - if (tslen == 0) - { - strcpy (ts, "0000-00-00 00:00:00 "); - tslen = 20; - } + /* since i know that %z/%Z is not available in strftime, i switch to sprintf immediately */ + tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); #else #if defined(__OS2__) tmp = _localtime(&now, &tm); @@ -902,8 +893,7 @@ static void log_write (moo_t* moo, moo_bitmask_t mask, const moo_ooch_t* msg, mo #endif if (tslen == 0) { - strcpy (ts, "0000-00-00 00:00:00 +0000 "); - tslen = 26; + tslen = sprintf(ts, "%04d-%02d-%02d %02d:%02d:%02d ", tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); } #endif write_log (moo, logfd, ts, tslen);