LibC: Reimplement asctime() in terms of strftime()

This commit is contained in:
howar6hill 2020-03-08 17:00:58 +08:00 committed by Andreas Kling
commit df40847c52
Notes: sideshowbarker 2024-07-19 17:37:24 +09:00

View file

@ -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.