static void f_obs(char *arg) { if (!(ddflags & C_BS)) out.dbsz = get_bsz(arg); }
static void f_count(char *arg) { if ((cpy_cnt = get_bsz(arg)) == 0) cpy_cnt = (size_t)-1; }
static void f_ibs(char *arg) { if (!(ddflags & C_BS)) in.dbsz = get_bsz(arg); }
/* * Convert an expression of the following forms to a size_t * 1) A positive decimal number. * 2) A positive decimal number followed by a b (mult by 512). * 3) A positive decimal number followed by a k (mult by 1024). * 4) A positive decimal number followed by a m (mult by 1048576). * 5) A positive decimal number followed by a w (mult by sizeof int) * 6) Two or more positive decimal numbers (with/without k,b or w). * separated by x (also * for backwards compatibility), specifying * the product of the indicated values. */ static size_t get_bsz(char *val) { size_t num, t; char *expr; num = strtoul(val, &expr, 0); if (num == SIZE_T_MAX) /* Overflow. */ err(1, "%s", oper); if (expr == val) /* No digits. */ errx(1, "%s: illegal numeric value", oper); switch(*expr) { case 'b': t = num; num *= 512; if (t > num) goto erange; ++expr; break; case 'k': case 'K': t = num; num *= 1024; if (t > num) goto erange; ++expr; break; case 'm': case 'M': t = num; num *= 1048576; if (t > num) goto erange; ++expr; break; case 'w': t = num; num *= sizeof(int); if (t > num) goto erange; ++expr; break; } switch(*expr) { case '\0': break; case '*': /* Backward compatible. */ case 'x': t = num; num *= get_bsz(expr + 1); if (t > num) erange: errx(1, "%s: %s", oper, strerror(ERANGE)); break; default: errx(1, "%s: illegal numeric value", oper); } return (num); }
static void f_files(char *arg) { files_cnt = get_bsz(arg); }
static void f_cbs(char *arg) { cbsz = get_bsz(arg); }
static void f_bs(char *arg) { in.dbsz = out.dbsz = get_bsz(arg); }
/* * Convert an expression of the following forms to a size_t * 1) A positive decimal number, optionally followed by * b - multiply by 512. * k, m or g - multiply by 1024 each. * w - multiply by sizeof int * 2) Two or more of the above, separated by x * (or * for backwards compatibility), specifying * the product of the indicated values. */ static size_t get_bsz(char *val) { size_t num, t; char *expr; if (strchr(val, '-')) errx(1, "%s: illegal numeric value", oper); errno = 0; num = strtoul(val, &expr, 0); if (num == ULONG_MAX && errno == ERANGE) /* Overflow. */ err(1, "%s", oper); if (expr == val) /* No digits. */ errx(1, "%s: illegal numeric value", oper); switch(*expr) { case 'b': t = num; num *= 512; if (t > num) goto erange; ++expr; break; case 'g': case 'G': t = num; num *= 1024; if (t > num) goto erange; /* fallthrough */ case 'm': case 'M': t = num; num *= 1024; if (t > num) goto erange; /* fallthrough */ case 'k': case 'K': t = num; num *= 1024; if (t > num) goto erange; ++expr; break; case 'w': t = num; num *= sizeof(int); if (t > num) goto erange; ++expr; break; } switch(*expr) { case '\0': break; case '*': /* Backward compatible. */ case 'x': t = num; num *= get_bsz(expr + 1); if (t > num) goto erange; break; default: errx(1, "%s: illegal numeric value", oper); } return (num); erange: errc(1, ERANGE, "%s", oper); }