On 2025/7/4 11:33, Darrick J. Wong worte:
On Fri, Jul 04, 2025 at 10:11:09AM +0800, zhanchengbin wrote:
On 2025/7/3 23:39, Darrick J. Wong wrote:
On Thu, Jul 03, 2025 at 08:07:53PM +0800, zhanchengbin wrote:
+static void dump_commit_time(FILE *out_file, char *buf)
+{
+ struct commit_header *header;
+ uint64_t commit_sec;
+ time_t timestamp;
+ char time_buffer[26];
+ char *result;
+
+ header = (struct commit_header *)buf;
+ commit_sec = be64_to_cpu(header->h_commit_sec);
+
+ timestamp = commit_sec;
+ result = ctime_r(×tamp, time_buffer);
+ if (result)
+ fprintf(out_file, ", commit at: %s", time_buffer);
Nit: missing newline in this fprintf... or you could delete the newline
below and change the callsite to:
if (dump_time)
dump_commit_time(out_file, buf);
fprintf(out_file, "\n");
In my test environment, the string generated by ctime_r comes with a
newline character at the end.
Oh, I guess that /is/ in the manpage:
Broken-down time is stored in the structure tm, described in
tm(3type).
The call ctime(t) is equivalent to asctime(localtime(t)). It
converts the calendar time t into a null-terminated string of
the form
"Wed Jun 30 21:49:08 1993\n"
and then POSIX has this to say about asctime():
The asctime() function shall convert the broken-down time in the
structure pointed to by timeptr into a string in the form:
Sun Sep 16 01:03:52 1973\n\0
which is also in ISO C23:
The asctime function converts the broken-down time in the
structure pointed to by timeptr into a string in the form:
Sun Sep 16 01:03:52 1973\n\0
using the equivalent of the following algorithm.
Get it.
Sigh.
Reviewed-by: "Darrick J. Wong" <djwong@xxxxxxxxxx>
Thanks,
- bin.
.
.