bin/50988: [Patch] find -size -- express argument in kilo, mega... bytes

Matthew Seaman m.seaman at infracaninophile.co.uk
Tue Apr 15 07:50:20 PDT 2003


The following reply was made to PR bin/50988; it has been noted by GNATS.

From: Matthew Seaman <m.seaman at infracaninophile.co.uk>
To: FreeBSD-gnats-submit at FreeBSD.org
Cc:  
Subject: Re: bin/50988: [Patch] find -size -- express argument in kilo, mega... bytes
Date: Tue, 15 Apr 2003 15:45:00 +0100

 --17pEHd4RhPHOinZp
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Sheesh.  This patch has the correct values for giga and peta byte scaling:
 
 --- function.c.orig	Tue Apr 15 11:59:51 2003
 +++ function.c	Tue Apr 15 15:39:31 2003
 @@ -136,7 +136,7 @@
  	value =3D strtoq(str, &endchar, 10);
  	if (value =3D=3D 0 && endchar =3D=3D str)
  		errx(1, "%s: %s: illegal numeric value", option, vp);
 -	if (endchar[0] && (endch =3D=3D NULL || endchar[0] !=3D *endch))
 +	if (endchar[0] && endch =3D=3D NULL)
  		errx(1, "%s: %s: illegal trailing character", option, vp);
  	if (endch)
  		*endch =3D endchar[0];
 @@ -1349,7 +1349,8 @@
   *
   *	True if the file size in bytes, divided by an implementation defined
   *	value and rounded up to the next integer, is n.  If n is followed by
 - *	a c, the size is in bytes.
 + *	one of c k M G T P, the size is in bytes, kilobytes, megabytes,
 + *	gigabytes, terabytes or petabytes respectively.
   */
  #define	FIND_SIZE	512
  static int divsize =3D 1;
 @@ -1374,15 +1375,46 @@
  	char *size_str;
  	PLAN *new;
  	char endch;
 -
 +	off_t scale;
 +=09
  	size_str =3D nextarg(option, argvp);
  	ftsoptions &=3D ~FTS_NOSTAT;
 =20
  	new =3D palloc(option);
  	endch =3D 'c';
  	new->o_data =3D find_parsenum(new, option->name, size_str, &endch);
 -	if (endch =3D=3D 'c')
 +	if (endch !=3D '\0') {
  		divsize =3D 0;
 +
 +		switch (endch) {
 +		case 'c':			/* characters */
 +			scale =3D 0x1LL;
 +			break;
 +		case 'k':			/* kilobytes 1<<10 */
 +			scale =3D 0x400LL;
 +			break;
 +		case 'M':			/* megabytes 1<<20 */
 +			scale =3D 0x100000LL;
 +			break;
 +		case 'G':			/* gigabytes 1<<30 */
 +			scale =3D 0x40000000LL;
 +			break;
 +		case 'T':			/* terabytes 1<<40 */
 +			scale =3D 0x1000000000LL;
 +			break;
 +		case 'P':			/* petabytes 1<<50 */
 +			scale =3D 0x4000000000000LL;
 +			break;
 +		default:
 +			errx(1, "%s: %s: illegal trailing character",
 +			     option->name, size_str);
 +			break;
 +		}
 +		if (new->o_data > QUAD_MAX / scale)
 +			errx(1, "%s: %s: value too large",
 +			     option->name, size_str);
 +		new->o_data *=3D scale;
 +	}
  	return new;
  }
 =20
 
 	Cheers,
 
 	Matthew
 
 --=20
 Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                       Savill Way
 PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
 Tel: +44 1628 476614                                  Bucks., SL7 1TH UK
 
 --17pEHd4RhPHOinZp
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.1 (FreeBSD)
 
 iD8DBQE+nBrsdtESqEQa7a0RAlK7AJ9IgPzgbpZ5tGsX2e04v7ldY6tTvgCcCV3K
 BTk/8r7qkub9dWCOfPDYwu0=
 =7XFv
 -----END PGP SIGNATURE-----
 
 --17pEHd4RhPHOinZp--


More information about the freebsd-bugs mailing list