iputils-20121221-printf-size.patch 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. Since the printf funcs already return the length of chars displayed,
  6. use that value instead of re-calculating the length with strlen.
  7. This also fixes the handling of the strlen return -- it's a size_t,
  8. not an int.
  9. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
  10. ---
  11. tracepath.c | 11 ++++-------
  12. tracepath6.c | 11 ++++-------
  13. 2 files changed, 8 insertions(+), 14 deletions(-)
  14. diff --git a/tracepath.c b/tracepath.c
  15. index 8a08f1d..f155816 100644
  16. --- a/tracepath.c
  17. +++ b/tracepath.c
  18. @@ -73,13 +73,10 @@ void data_wait(int fd)
  19. void print_host(const char *a, const char *b, int both)
  20. {
  21. - int plen = 0;
  22. - printf("%s", a);
  23. - plen = strlen(a);
  24. - if (both) {
  25. - printf(" (%s)", b);
  26. - plen += strlen(b) + 3;
  27. - }
  28. + int plen;
  29. + plen = printf("%s", a);
  30. + if (both)
  31. + plen += printf(" (%s)", b);
  32. if (plen >= HOST_COLUMN_SIZE)
  33. plen = HOST_COLUMN_SIZE - 1;
  34. printf("%*s", HOST_COLUMN_SIZE - plen, "");
  35. diff --git a/tracepath6.c b/tracepath6.c
  36. index 126fadf..bee95c3 100644
  37. --- a/tracepath6.c
  38. +++ b/tracepath6.c
  39. @@ -86,13 +86,10 @@ void data_wait(int fd)
  40. void print_host(const char *a, const char *b, int both)
  41. {
  42. - int plen = 0;
  43. - printf("%s", a);
  44. - plen = strlen(a);
  45. - if (both) {
  46. - printf(" (%s)", b);
  47. - plen += strlen(b) + 3;
  48. - }
  49. + int plen;
  50. + plen = printf("%s", a);
  51. + if (both)
  52. + plen += printf(" (%s)", b);
  53. if (plen >= HOST_COLUMN_SIZE)
  54. plen = HOST_COLUMN_SIZE - 1;
  55. printf("%*s", HOST_COLUMN_SIZE - plen, "");
  56. --
  57. 1.8.0.2