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);
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;
+ }