]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - misc/nstat.c
Merge branch 'master' of git://git.kernel.org/pub/scm/network/iproute2/iproute2-next
[mirror_iproute2.git] / misc / nstat.c
index ffa14b1e159608db86a718c90582b07521d92749..23113b223b22d5db1c82bf28c26105936ee6776b 100644 (file)
@@ -177,12 +177,14 @@ static int count_spaces(const char *line)
 
 static void load_ugly_table(FILE *fp)
 {
-       char buf[4096];
+       char *buf = NULL;
+       size_t buflen = 0;
+       ssize_t nread;
        struct nstat_ent *db = NULL;
        struct nstat_ent *n;
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               char idbuf[sizeof(buf)];
+       while ((nread = getline(&buf, &buflen, fp)) != -1) {
+               char idbuf[4096];
                int  off;
                char *p;
                int count1, count2, skip = 0;
@@ -218,7 +220,8 @@ static void load_ugly_table(FILE *fp)
                        p = next;
                }
                n = db;
-               if (fgets(buf, sizeof(buf), fp) == NULL)
+               nread = getline(&buf, &buflen, fp);
+               if (nread == -1)
                        abort();
                count2 = count_spaces(buf);
                if (count2 > count1)
@@ -237,6 +240,7 @@ static void load_ugly_table(FILE *fp)
                                n = n->next;
                } while (p > buf + off + 2);
        }
+       free(buf);
 
        while (db) {
                n = db;
@@ -524,18 +528,18 @@ static void usage(void) __attribute__((noreturn));
 static void usage(void)
 {
        fprintf(stderr,
-"Usage: nstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
-"   -h, --help           this message\n"
-"   -a, --ignore         ignore history\n"
-"   -d, --scan=SECS      sample every statistics every SECS\n"
-"   -j, --json           format output in JSON\n"
-"   -n, --nooutput       do history only\n"
-"   -p, --pretty         pretty print\n"
-"   -r, --reset          reset history\n"
-"   -s, --noupdate       don't update history\n"
-"   -t, --interval=SECS  report average over the last SECS\n"
-"   -V, --version        output version information\n"
-"   -z, --zeros          show entries with zero activity\n");
+               "Usage: nstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
+               "   -h, --help          this message\n"
+               "   -a, --ignore        ignore history\n"
+               "   -d, --scan=SECS     sample every statistics every SECS\n"
+               "   -j, --json          format output in JSON\n"
+               "   -n, --nooutput      do history only\n"
+               "   -p, --pretty        pretty print\n"
+               "   -r, --reset         reset history\n"
+               "   -s, --noupdate      don't update history\n"
+               "   -t, --interval=SECS report average over the last SECS\n"
+               "   -V, --version       output version information\n"
+               "   -z, --zeros         show entries with zero activity\n");
        exit(-1);
 }