From 0fcff3686b2759a5962aec115d42856976db5e5c Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 7 Aug 2008 14:48:35 +0000 Subject: Use humanize_number to report pen-sizes so people don't have to count the digits when trying to install openoffice. --- usr.sbin/pkg_install/Makefile.inc | 3 +++ usr.sbin/pkg_install/lib/pen.c | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/usr.sbin/pkg_install/Makefile.inc b/usr.sbin/pkg_install/Makefile.inc index bff3474..2fa20aa 100644 --- a/usr.sbin/pkg_install/Makefile.inc +++ b/usr.sbin/pkg_install/Makefile.inc @@ -4,6 +4,9 @@ LIBINSTALL= ${.OBJDIR}/../lib/libinstall.a +DPADD+= ${LIBUTIL} +LDADD+= -lutil + .if ${MK_OPENSSL} != "no" && \ defined(LDADD) && ${LDADD:M-lfetch} != "" DPADD+= ${LIBSSL} ${LIBCRYPTO} diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 06379b6..fef3f9d 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -23,6 +23,7 @@ __FBSDID("$FreeBSD$"); #include "lib.h" #include +#include #include #include #include @@ -44,6 +45,7 @@ find_play_pen(char *pen, off_t sz) { char *cp; struct stat sb; + char humbuf[6]; if (pen[0] && isdir(dirname(pen)) == TRUE && (min_free(dirname(pen)) >= sz)) return pen; @@ -59,10 +61,12 @@ find_play_pen(char *pen, off_t sz) strcpy(pen, "/usr/tmp/instmp.XXXXXX"); else { cleanup(0); + humanize_number(humbuf, sizeof humbuf, sz, "", HN_AUTOSCALE, + HN_NOSPACE); errx(2, "%s: can't find enough temporary space to extract the files, please set your\n" -"PKG_TMPDIR environment variable to a location with at least %ld bytes\n" -"free", __func__, (long)sz); +"PKG_TMPDIR environment variable to a location with at least %s bytes\n" +"free", __func__, humbuf); return NULL; } return pen; @@ -98,6 +102,8 @@ popPen(char *pen) char * make_playpen(char *pen, off_t sz) { + char humbuf1[6], humbuf2[6]; + if (!find_play_pen(pen, sz)) return NULL; @@ -111,8 +117,13 @@ make_playpen(char *pen, off_t sz) } if (Verbose) { - if (sz) - fprintf(stderr, "Requested space: %d bytes, free space: %lld bytes in %s\n", (int)sz, (long long)min_free(pen), pen); + if (sz) { + humanize_number(humbuf1, sizeof humbuf1, sz, "", HN_AUTOSCALE, + HN_NOSPACE); + humanize_number(humbuf2, sizeof humbuf2, min_free(pen), + "", HN_AUTOSCALE, HN_NOSPACE); + fprintf(stderr, "Requested space: %s bytes, free space: %s bytes in %s\n", humbuf1, humbuf2, pen); + } } if (min_free(pen) < sz) { -- cgit v1.1