public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin/main] Cygwin: cygcheck: add human readable package size output
@ 2023-01-29 16:52 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2023-01-29 16:52 UTC (permalink / raw)
To: cygwin-cvs
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=c67e6570eef5b745e23d8c9449062b0f9f6c8cc4
commit c67e6570eef5b745e23d8c9449062b0f9f6c8cc4
Author: Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sun Jan 29 17:21:28 2023 +0100
Commit: Corinna Vinschen <corinna@vinschen.de>
CommitDate: Sun Jan 29 17:21:28 2023 +0100
Cygwin: cygcheck: add human readable package size output
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/utils/mingw/cygcheck.cc | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/winsup/utils/mingw/cygcheck.cc b/winsup/utils/mingw/cygcheck.cc
index ed1d8f85a2d2..17a7669197df 100644
--- a/winsup/utils/mingw/cygcheck.cc
+++ b/winsup/utils/mingw/cygcheck.cc
@@ -14,6 +14,7 @@
#include <sys/stat.h>
#include <ctype.h>
#include <fcntl.h>
+#include <math.h>
#include <io.h>
#include <windows.h>
#include <wininet.h>
@@ -2343,6 +2344,27 @@ error:
return NULL;
}
+static const char *
+human_readable (char *buf, size_t bytes)
+{
+ const char *siz[] = { "B", "K", "M", "G", NULL };
+ double db = bytes;
+ int idx = 0;
+ int prec;
+
+ while (bytes > 1023 && siz[idx + 1])
+ {
+ bytes >>= 10;
+ db /= 1024.0;
+ ++idx;
+ }
+ prec = log10 (db) + 1;
+ if (prec < 2)
+ prec = 2;
+ sprintf (buf, "%.*g %s", prec, db, siz[idx]);
+ return buf;
+}
+
static void
package_info_print (ini_package_info *pi, vers_info *vers)
{
@@ -2364,7 +2386,9 @@ package_info_print (ini_package_info *pi, vers_info *vers)
if (vers->install)
{
char *arch = strcpy (buf, vers->install);
- char *size = NULL;
+ char *sizep;
+ size_t size = 0;
+
char *cp;
cp = strchr (arch, '/');
@@ -2374,10 +2398,13 @@ package_info_print (ini_package_info *pi, vers_info *vers)
cp = strchr (cp, ' ');
if (cp)
{
- size = ++cp;
+ sizep = ++cp;
cp = strchr (cp, ' ');
if (cp)
- *cp = '\0';
+ {
+ *cp = '\0';
+ size = strtoull (sizep, NULL, 10);
+ }
}
}
if (cp)
@@ -2385,7 +2412,9 @@ package_info_print (ini_package_info *pi, vers_info *vers)
printf ("Architecture: %s\n", arch);
if (vers->install_date)
printf ("Install Date: %s", ctime (&vers->install_date));
- printf ("Size : %s\n", size); /* FIXME: human-readable */
+
+ printf ("Size : %llu (%s)\n", size,
+ human_readable (buf, size));
}
}
if (vers->source)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-01-29 16:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-29 16:52 [newlib-cygwin/main] Cygwin: cygcheck: add human readable package size output Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).