]> rtime.felk.cvut.cz Git - can-utils.git/commitdiff
candump: reduce printf calls for logfile format
authorOliver Hartkopp <socketcan@hartkopp.net>
Mon, 5 May 2014 19:29:56 +0000 (21:29 +0200)
committerOliver Hartkopp <socketcan@hartkopp.net>
Mon, 5 May 2014 19:29:56 +0000 (21:29 +0200)
The creation of the logfile format was using fprint_canframe() and two other
fprintf() calls to produce a single logfile format line. Instead of using
fprint_canframe() use sprint_canframe() directly and reduce the printf() calls
from three to one.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
candump.c

index c865bd76f9dd78f41b99bbdae31b1067ab411809..b67f3f8ecdf460b324a5e6fc60930fbec1197098 100644 (file)
--- a/candump.c
+++ b/candump.c
@@ -698,18 +698,23 @@ int main(int argc, char **argv)
                                        view |= CANLIB_VIEW_INDENT_SFF;
 
                                if (log) {
+                                       char buf[CL_CFSZ]; /* max length */
+
                                        /* log CAN frame with absolute timestamp & device */
-                                       fprintf(logfile, "(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec);
-                                       fprintf(logfile, "%*s ", max_devname_len, devname[idx]);
-                                       /* without separator as logfile use-case is parsing */
-                                       fprint_canframe(logfile, &frame, "\n", 0, maxdlen);
+                                       sprint_canframe(buf, &frame, 0, maxdlen);
+                                       fprintf(logfile, "(%010ld.%06ld) %*s %s\n",
+                                               tv.tv_sec, tv.tv_usec,
+                                               max_devname_len, devname[idx], buf);
                                }
 
                                if (logfrmt) {
+                                       char buf[CL_CFSZ]; /* max length */
+
                                        /* print CAN frame in log file style to stdout */
-                                       printf("(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec);
-                                       printf("%*s ", max_devname_len, devname[idx]);
-                                       fprint_canframe(stdout, &frame, "\n", 0, maxdlen);
+                                       sprint_canframe(buf, &frame, 0, maxdlen);
+                                       printf("(%010ld.%06ld) %*s %s\n",
+                                              tv.tv_sec, tv.tv_usec,
+                                              max_devname_len, devname[idx], buf);
                                        goto out_fflush; /* no other output to stdout */
                                }