From df40847c523c718990c4e20714057654cdad319b Mon Sep 17 00:00:00 2001 From: howar6hill Date: Sun, 8 Mar 2020 17:00:58 +0800 Subject: [PATCH] LibC: Reimplement asctime() in terms of strftime() --- Libraries/LibC/time.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Libraries/LibC/time.cpp b/Libraries/LibC/time.cpp index 91b97f10f8..0c011f5176 100644 --- a/Libraries/LibC/time.cpp +++ b/Libraries/LibC/time.cpp @@ -168,14 +168,9 @@ static char mon_long_names[12][10] = { char* asctime(const struct tm* tm) { - constexpr int maxLength = 69; - StringBuilder builder { maxLength }; - builder.appendf("%.3s %.3s %2d %02d:%02d:%02d %4d\n", wday_short_names[tm->tm_wday], - mon_short_names[tm->tm_mon], tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, 1900 + tm->tm_year); - - static char result[maxLength]; - strncpy(result, builder.build().characters(), sizeof result); - return result; + static char buffer[69]; + strftime(buffer, sizeof buffer, "%a %b %e %T %Y", tm); + return buffer; } //FIXME: Some formats are not supported.