[PATCH v2 4/7] misc: syslog: Simplify implementation
Paul Eggert
eggert@cs.ucla.edu
Sat Feb 19 03:15:37 GMT 2022
On 2/18/22 06:23, Adhemerval Zanella via Libc-alpha wrote:
> + char timebuf[3+1 /* "%h " */
> + + 2+1 /* "%e " */
> + + 2+1 + 2+1 + 2+1 + 1 /* "%T " */];
> + time_t now = time_now ();
> + struct tm now_tm;
> + __localtime_r (&now, &now_tm);
> + __strftime_l (timebuf, sizeof (timebuf), "%h %e %T ", &now_tm,
> + _nl_C_locobj_ptr);
> +
> + pid_t pid = LogStat & LOG_PID ? __getpid () : 0;
> +
> + fprintf (f, "<%d>%s %n%s%s%.0d%s: ", pri, timebuf, &msgoff,
Doesn't this output two spaces after the expansion of "%T"? The old code
output just one.
Also, the old code crashed when __localtime_r returns NULL, whereas the
new code logs garbage that might be truncated in 'timebuf'; is that
change intended?
More information about the Libc-alpha
mailing list