Hi,
The following patch recognizes alternative postfixes to find(1) -size.
Index: find.1
===================================================================
RCS file: /cvs/src/usr.bin/find/find.1,v
retrieving revision 1.85
diff -u -p -r1.85 find.1
--- find.1 5 Jan 2012 13:16:10 -0000 1.85
+++ find.1 4 Nov 2012 07:25:59 -0000
@@ -447,16 +447,26 @@ primary has no effect if the
option was specified.
.Pp
.It Ic -size Ar n Ns Op Cm c
-True if the file's size, rounded up, in 512-byte blocks is
+True if the file's size, rounded up in the nearest unit size, is
.Ar n .
-If
-.Ar n
-is followed by a
-.Sq c ,
-then the primary is true if the
-file's size is
-.Ar n
-bytes.
+The default unit size is 512 bytes.
+.Pp
+The following postfixes which modify the unit size are recognize:
+.Pp
+.Bl -tag -width cxx -offset indent -compact
+.It Cm c
+bytes
+.It Cm k
+kilobytes
+.It Cm m
+megabytes
+.It Cm g
+gigabytes
+.It Cm t
+terabytes
+.It Cm p
+petabytes
+.El
.Pp
.It Ic -type Ar t
True if the file is of the specified type.
Index: function.c
===================================================================
RCS file: /cvs/src/usr.bin/find/function.c,v
retrieving revision 1.38
diff -u -p -r1.38 function.c
--- function.c 5 Jan 2012 10:21:33 -0000 1.38
+++ function.c 4 Nov 2012 07:26:00 -0000
@@ -48,6 +48,7 @@
#include <libgen.h>
#include <limits.h>
#include <pwd.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -71,7 +72,7 @@
}
static PLAN *palloc(enum ntype, int (*)(PLAN *, FTSENT *));
-static long find_parsenum(PLAN *plan, char *option, char *vp, char *endch);
+static long find_parsenum(PLAN *plan, char *option, char *vp, char **endch);
static void run_f_exec(PLAN *plan);
static PLAN *palloc(enum ntype t, int (*f)(PLAN *, FTSENT *));
@@ -122,7 +123,7 @@ extern FTS *tree;
* Parse a string of the form [+-]# and return the value.
*/
static long
-find_parsenum(PLAN *plan, char *option, char *vp, char *endch)
+find_parsenum(PLAN *plan, char *option, char *vp, char **endp)
{
long value;
char *endchar, *str; /* Pointer to character ending conversion. */
@@ -151,10 +152,8 @@ find_parsenum(PLAN *plan, char *option,
value = strtol(str, &endchar, 10);
if (value == 0 && endchar == str)
errx(1, "%s: %s: illegal numeric value", option, vp);
- if (endchar[0] && (endch == NULL || endchar[0] != *endch))
- errx(1, "%s: %s: illegal trailing character", option, vp);
- if (endch)
- *endch = endchar[0];
+ if (endp)
+ *endp = endchar;
return (value);
}
@@ -1375,35 +1374,63 @@ c_prune(char *ignore, char ***ignored, i
* -size n[c] functions --
*
* 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.
+ * value and rounded up to the next integer, is n.
+ *
+ * The following postfixes are supported:
+ * c - bytes
+ * k - kilobytes
+ * m - megabytes
+ * g - gigabytes
+ * t - terabytes
+ * p - petabytes
*/
#define FIND_SIZE 512
-static int divsize = 1;
+static uint64_t divsize = FIND_SIZE;
int
f_size(PLAN *plan, FTSENT *entry)
{
- off_t size;
-
- size = divsize ? (entry->fts_statp->st_size + FIND_SIZE - 1) /
- FIND_SIZE : entry->fts_statp->st_size;
- COMPARE(size, plan->o_data);
+ COMPARE(howmany(entry->fts_statp->st_size, divsize),
+ plan->o_data);
}
PLAN *
c_size(char *arg, char ***ignored, int unused)
{
PLAN *new;
- char endch;
+ char *endp;
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_SIZE, f_size);
- endch = 'c';
- new->o_data = find_parsenum(new, "-size", arg, &endch);
- if (endch == 'c')
- divsize = 0;
+ new->o_data = find_parsenum(new, "-size", arg, &endp);
+ if (endp) {
+ if (strlen(endp) > 1)
+ errx(1, "invalid postfix '%s'", endp);
+
+ switch (*endp) {
+ case 'c':
+ divsize = 1;
+ break;
+ case 'k':
+ divsize = 1024;
+ break;
+ case 'm':
+ divsize = 1024 * 1024;
+ break;
+ case 'g':
+ divsize = 1024 * 1024 * UINT64_C(1024);
+ break;
+ case 't':
+ divsize = 1024 * 1024 * UINT64_C(1024) * 1024;
+ break;
+ case 'p':
+ divsize = 1024 * 1024 * UINT64_C(1024) * 1024 * 1024;
+ break;
+ default:
+ errx(1, "unknown postfix '%c'", *endp);
+ }
+ }
return (new);
}
[demime 1.01d removed an attachment of type application/pgp-signature]