t005-printf-size.diff - mkports - recipes for building multiple softwares with mk(1)
 (HTM) git clone git://z3bra.org/mkports
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       t005-printf-size.diff (1671B)
       ---
            1 From 23fcb10ae15a96aa9e5a823cfe0b612d9522691c Mon Sep 17 00:00:00 2001
            2 From: Mike Frysinger <vapier@gentoo.org>
            3 Date: Sat, 14 Aug 2010 01:16:42 -0400
            4 Subject: [PATCH [iputils]] tracepath: re-use printf return in print_host
            5 
            6 Since the printf funcs already return the length of chars displayed,
            7 use that value instead of re-calculating the length with strlen.
            8 
            9 This also fixes the handling of the strlen return -- it's a size_t,
           10 not an int.
           11 
           12 Signed-off-by: Mike Frysinger <vapier@gentoo.org>
           13 ---
           14  tracepath.c  | 11 ++++-------
           15  tracepath6.c | 11 ++++-------
           16  2 files changed, 8 insertions(+), 14 deletions(-)
           17 
           18 diff --git a/tracepath.c b/tracepath.c
           19 index 8a08f1d..f155816 100644
           20 --- a/tracepath.c
           21 +++ b/tracepath.c
           22 @@ -73,13 +73,10 @@ void data_wait(int fd)
           23  
           24  void print_host(const char *a, const char *b, int both)
           25  {
           26 -        int plen = 0;
           27 -        printf("%s", a);
           28 -        plen = strlen(a);
           29 -        if (both) {
           30 -                printf(" (%s)", b);
           31 -                plen += strlen(b) + 3;
           32 -        }
           33 +        int plen;
           34 +        plen = printf("%s", a);
           35 +        if (both)
           36 +                plen += printf(" (%s)", b);
           37          if (plen >= HOST_COLUMN_SIZE)
           38                  plen = HOST_COLUMN_SIZE - 1;
           39          printf("%*s", HOST_COLUMN_SIZE - plen, "");
           40 diff --git a/tracepath6.c b/tracepath6.c
           41 index 126fadf..bee95c3 100644
           42 --- a/tracepath6.c
           43 +++ b/tracepath6.c
           44 @@ -86,13 +86,10 @@ void data_wait(int fd)
           45  
           46  void print_host(const char *a, const char *b, int both)
           47  {
           48 -        int plen = 0;
           49 -        printf("%s", a);
           50 -        plen = strlen(a);
           51 -        if (both) {
           52 -                printf(" (%s)", b);
           53 -                plen += strlen(b) + 3;
           54 -        }
           55 +        int plen;
           56 +        plen = printf("%s", a);
           57 +        if (both)
           58 +                plen += printf(" (%s)", b);
           59          if (plen >= HOST_COLUMN_SIZE)
           60                  plen = HOST_COLUMN_SIZE - 1;
           61          printf("%*s", HOST_COLUMN_SIZE - plen, "");
           62 -- 
           63 1.8.0.2
           64