This is an archive of the discontinued LLVM Phabricator instance.

[libc] Introduce asctime, asctime_r to LLVM libc
ClosedPublic

Authored by rtenneti on Mar 31 2021, 2:07 PM.

Details

Summary

[libc] Introduce asctime, asctime_r to LLVM libc

asctime and asctime_r share the same common code. They call asctime_internal
a static inline function.

asctime uses snprintf to return the string representation in a buffer.
It uses the following format (26 characters is the buffer size) as per
7.27.3.1 section in http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2478.pdf.
The buf parameter for asctime_r shall point to a buffer of at least 26 bytes.

snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",...)

Diff Detail

Event Timeline

rtenneti created this revision.Mar 31 2021, 2:07 PM
rtenneti requested review of this revision.Mar 31 2021, 2:07 PM
rtenneti updated this revision to Diff 338638.Apr 19 2021, 2:13 PM

Used __builtin_snprintf. Thanks Siva for the idea.

sivachandra accepted this revision.Apr 26 2021, 11:18 PM

Sorry for the long delay. I have a nitty comment inline. Also, can you please change the way the subject line is written: Instead of "Introduces asctime, asctime_r to LLVM libc, based on C99/C2X/Single Unix Sp.", can you change it to, "Introduce asctime, asctime_r to LLVM libc". Change the rest of the description in a similar way.

libc/src/time/time_utils.h
78

Nit: Should this function name have the _internal suffix? It is already in an internal namespace time_utils.

This revision is now accepted and ready to land.Apr 26 2021, 11:18 PM
rtenneti updated this revision to Diff 342597.May 3 2021, 5:04 PM
rtenneti marked an inline comment as done.

Changed the internal asctime_internal to asctime.

rtenneti retitled this revision from [libc] Introduces asctime, asctime_r to LLVM libc, based on C99/C2X/Single Unix Sp. to [libc] Introduce asctime, asctime_r to LLVM libc.May 3 2021, 5:07 PM
rtenneti edited the summary of this revision. (Show Details)

Thanks for comments Siva. Made all the changes you have suggested.

This revision was landed with ongoing or failed builds.May 3 2021, 5:15 PM
This revision was automatically updated to reflect the committed changes.