I'm sorry, patch now attached.
From 6f780659d237c89926af7d70ab31f29be6931092 Mon Sep 17 00:00:00 2001 From: Pere Orga <[email protected]> Date: Tue, 26 Jul 2011 21:19:18 +0200 Subject: [PATCH] top: parse /proc/meminfo differently, save 114 bytes
Signed-off-by: Pere Orga <[email protected]> --- procps/top.c | 47 +++++++++++++++++------------------------------ 1 files changed, 17 insertions(+), 30 deletions(-) diff --git a/procps/top.c b/procps/top.c index 011bbf1..cb74232 100644 --- a/procps/top.c +++ b/procps/top.c @@ -449,8 +449,7 @@ static unsigned long display_header(int scr_width, int *lines_rem_p) /* * Old kernels (such as 2.4.x) had a nice summary of memory info that - * we could parse, however this is gone entirely in 2.6. Try parsing - * the old way first, and if that fails, parse each field manually. + * we could parse, however this is gone entirely in 2.6. * * First, we read in the first line. Old kernels will have bogus * strings we don't care about, whereas new kernels will start right @@ -458,37 +457,25 @@ static unsigned long display_header(int scr_width, int *lines_rem_p) * -- PFM. */ if (fscanf(fp, "MemTotal: %lu %s\n", &total, buf) != 2) { - fgets(buf, sizeof(buf), fp); /* skip first line */ - - fscanf(fp, "Mem: %lu %lu %lu %lu %lu %lu", - &total, &used, &mfree, &shared, &buffers, &cached); - /* convert to kilobytes */ - used /= 1024; - mfree /= 1024; - shared /= 1024; - buffers /= 1024; - cached /= 1024; - total /= 1024; - } else { - /* - * Revert to manual parsing, which incidentally already has the - * sizes in kilobytes. This should be safe for both 2.4 and - * 2.6. - */ - fscanf(fp, "MemFree: %lu %s\n", &mfree, buf); + fgets(buf, sizeof(buf), fp); /* skip first lines */ + fgets(buf, sizeof(buf), fp); + fgets(buf, sizeof(buf), fp); + fscanf(fp, "MemTotal: %lu %s\n", &total, buf); + } + fscanf(fp, "MemFree: %lu %s\n", &mfree, buf); - /* - * MemShared: is no longer present in 2.6. Report this as 0, - * to maintain consistent behavior with normal procps. - */ - if (fscanf(fp, "MemShared: %lu %s\n", &shared, buf) != 2) - shared = 0; + /* + * MemShared: is no longer present in 2.6. Report this as 0, + * to maintain consistent behavior with normal procps. + */ + if (fscanf(fp, "MemShared: %lu %s\n", &shared, buf) != 2) + shared = 0; - fscanf(fp, "Buffers: %lu %s\n", &buffers, buf); - fscanf(fp, "Cached: %lu %s\n", &cached, buf); + fscanf(fp, "Buffers: %lu %s\n", &buffers, buf); + fscanf(fp, "Cached: %lu %s\n", &cached, buf); + + used = total - mfree; - used = total - mfree; - } fclose(fp); /* output memory info */ -- 1.7.2.5
_______________________________________________ busybox mailing list [email protected] http://lists.busybox.net/mailman/listinfo/busybox
