[systemd-devel] [PATCH 4/4] cgtop: support time header with user-specified format string
Filipe Brandenburger
filbranden at google.com
Wed May 27 16:58:35 PDT 2015
Hi,
On Wed, May 27, 2015 at 3:40 PM, Charles Duffy <charles at dyfis.net> wrote:
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wformat-nonliteral"
> + time_len = strftime(buf, l, arg_time_format, curr_time);
> + if (time_len <= 0)
> + return;
> +#pragma GCC diagnostic pop
You could instead use gcc's __attribute__ ((format (strftime, ...)))
to indicate that arg_time_format is supposed to be a valid strftime
format.
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bflatten_007d-function-attribute-3080
See also the definition of _printf_ in src/shared/macro.h and its uses.
Though I'm not sure whether taking a strftime format as a command line
argument is really a good idea... But I'll defer that to other
reviewers.
Cheers,
Filipe
More information about the systemd-devel
mailing list