extern void free_strings (char **argv);
extern void free_stringslen (char **argv, int len);
+extern int is_power_of_2 (unsigned long v);
+
#define command(out,err,name,...) commandf((out),(err),0,(name),__VA_ARGS__)
#define commandr(out,err,name,...) commandrf((out),(err),0,(name),__VA_ARGS__)
#define commandv(out,err,argv) commandvf((out),(err),0,(argv))
return argc;
}
+/* http://graphics.stanford.edu/~seander/bithacks.html#DetermineIfPowerOf2 */
+int
+is_power_of_2 (unsigned long v)
+{
+ return v && ((v & (v - 1)) == 0);
+}
+
static int
compare (const void *vp1, const void *vp2)
{
const char *extra[2];
char blocksize_s[32];
+ if (blocksize <= 0 || !is_power_of_2 (blocksize)) {
+ reply_with_error ("block size must be > 0 and a power of 2");
+ return -1;
+ }
+
snprintf (blocksize_s, sizeof blocksize_s, "%d", blocksize);
extra[0] = "-b";