]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
Merge remote-tracking branch 'main/main' into next
authorDavid Ahern <dsahern@kernel.org>
Sat, 5 Oct 2024 23:06:06 +0000 (23:06 +0000)
committerDavid Ahern <dsahern@kernel.org>
Sat, 5 Oct 2024 23:06:06 +0000 (23:06 +0000)
Fixed conflicts in lib/utils.c

Signed-off-by: David Ahern <dsahern@kernel.org>
1  2 
include/utils.h
lib/utils.c

diff --cc include/utils.h
Simple merge
diff --cc lib/utils.c
index 6cf990067e0e0e5e1cae8e2151fc2a3f0137b088,98c06ab6a652eb24632987ea0ec04c9ab6f8220f..66713251fb26e2f1fc15c29195f7798496d9bd94
  int resolve_hosts;
  int timestamp_short;
  int pretty;
 +int use_iec;
 +int human_readable;
  const char *_SL_ = "\n";
  
+ static int open_fds[5];
+ static int open_fds_cnt;
  static int af_byte_len(int af);
  static void print_time(char *buf, int len, __u32 time);
  static void print_time64(char *buf, int len, __s64 time);
@@@ -2021,42 -2021,22 +2024,61 @@@ FILE *generic_proc_open(const char *env
        return fopen(p, "r");
  }
  
 -
 +void print_num(FILE *fp, unsigned int width, uint64_t count)
 +{
 +      const char *prefix = "kMGTPE";
 +      const unsigned int base = use_iec ? 1024 : 1000;
 +      uint64_t powi = 1;
 +      uint16_t powj = 1;
 +      uint8_t precision = 2;
 +      char buf[64];
 +
 +      if (!human_readable || count < base) {
 +              fprintf(fp, "%*"PRIu64" ", width, count);
 +              return;
 +      }
 +
 +      /* increase value by a factor of 1000/1024 and print
 +       * if result is something a human can read
 +       */
 +      for (;;) {
 +              powi *= base;
 +              if (count / base < powi)
 +                      break;
 +
 +              if (!prefix[1])
 +                      break;
 +              ++prefix;
 +      }
 +
 +      /* try to guess a good number of digits for precision */
 +      for (; precision > 0; precision--) {
 +              powj *= 10;
 +              if (count / powi < powj)
 +                      break;
 +      }
 +
 +      snprintf(buf, sizeof(buf), "%.*f%c%s", precision,
 +               (double) count / powi, *prefix, use_iec ? "i" : "");
 +
 +      fprintf(fp, "%*s ", width, buf);
 +}
++
+ int open_fds_add(int fd)
+ {
+       if (open_fds_cnt >= ARRAY_SIZE(open_fds))
+               return -1;
+       open_fds[open_fds_cnt++] = fd;
+       return 0;
+ }
+ void open_fds_close(void)
+ {
+       int i;
+       for (i = 0; i < open_fds_cnt; i++)
+               close(open_fds[i]);
+       open_fds_cnt = 0;
+ }