From owner-freebsd-hackers@FreeBSD.ORG Thu Mar 1 23:38:22 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 1233) id BDF401065676; Thu, 1 Mar 2012 23:38:22 +0000 (UTC) Date: Thu, 1 Mar 2012 23:38:22 +0000 From: Alexander Best To: freebsd-hackers@freebsd.org Message-ID: <20120301233822.GA19709@freebsd.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="BXVAT5kNtrzKuDFl" Content-Disposition: inline Subject: small change to du, so it will accepts unit suffixes for negative thresholds X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Mar 2012 23:38:22 -0000 --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: inline hi there, i just noticed that du will not accepts something like the following: du -t-500M whereas du -t500M will work. i've attached a patch, which makes unit suffixes in connection with negative thresholds possible. cheers. alex --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="du.diff.txt" diff --git a/usr.bin/du/du.1 b/usr.bin/du/du.1 index 3db1367..01d2ec1 100644 --- a/usr.bin/du/du.1 +++ b/usr.bin/du/du.1 @@ -137,6 +137,10 @@ If is negative, display only entries for which size is less than the absolute value of .Ar threshold . +For both positive and negative values, +.Ar threshold +accepts unit suffixes +.Po see Fl h Li option Pc . .It Fl x File system mount points are not traversed. .El diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c index 7b47b71..51bfd07 100644 --- a/usr.bin/du/du.c +++ b/usr.bin/du/du.c @@ -175,13 +175,18 @@ main(int argc, char *argv[]) break; case 'r': /* Compatibility. */ break; - case 't' : + case 't': + if (strncmp(optarg, "-", 1) == 0) { + optarg++; + threshold_sign = -1; + } if (expand_number(optarg, &threshold) != 0 || threshold == 0) { warnx("invalid threshold: %s", optarg); usage(); - } else if (threshold < 0) - threshold_sign = -1; + } + if (threshold_sign == -1) + threshold = -threshold; break; case 'x': ftsoptions |= FTS_XDEV; --BXVAT5kNtrzKuDFl--