1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
14 void usage(char *prog)
16 printf("usage: %s owner filenamefmt count\n", prog);
17 printf(" %s owner filenamefmt start count\n", prog);
20 int main(int argc, char ** argv)
22 int i, rc = 0, mask = 0;
23 char format[4096], *fmt;
26 long begin = 0, count;
28 if (argc < 4 || argc > 5) {
33 mask = strtol(argv[1], NULL, 0);
35 if (strlen(argv[2]) > 4080) {
36 printf("name too long\n");
40 start = last = time(0);
43 count = strtol(argv[3], NULL, 0);
45 printf("count must be at least one\n");
49 begin = strtol(argv[3], NULL, 0);
50 count = strtol(argv[4], NULL, 0);
53 if (strchr(argv[2], '%')) {
56 sprintf(format, "%s%%d", argv[2]);
59 for (i = 0; i < count; i++, begin++) {
60 sprintf(filename, fmt, begin);
61 rc = chown(filename, mask, -1);
63 printf("chown (%s) error: %s\n",
64 filename, strerror(errno));
68 if ((i % 10000) == 0) {
69 printf(" - chowned %d (time %ld ; total %ld ; last "
70 "%ld)\n", i, time(0), time(0) - start,
75 printf("total: %d chowns in %ld seconds: %f chowns/second\n", i,
76 time(0) - start, ((float)i / (time(0) - start)));