+}
+
+static void usage(int status)
+{
+ fprintf(
+ status ? stderr : stdout,
+ "Usage: ddnuke [options] <dev>\n"
+ "\n"
+ "Options:\n"
+ " -o <offset> Position to start writing\n"
+ " -r Write three times: 0x00, then 0xaa, then 0x55\n"
+ );
+ exit(status);
+}
+
+int main(int argc, char *argv[])
+{
+ off_t offset = 0;
+ const char *file;
+ bool random = false;
+ int o;
+
+ setlocale(LC_NUMERIC, "en_US");
+
+ while ((o = getopt(argc, argv, "ho:r")) != -1) {
+ switch (o) {
+ case 'o':
+ offset = atoll(optarg);
+ break;
+ case 'r':
+ random = true;
+ break;
+ case 'h': usage(EX_OK);
+ default: usage(EX_USAGE);
+ }
+ }
+ if (argc != optind + 1)
+ usage(EX_USAGE);
+ file = argv[optind];
+
+ int fd = open(file, O_WRONLY|O_CLOEXEC);
+ if (fd == -1)
+ errp("open(%s) failed", file);
+
+ off_t max_size = get_size(fd);
+
+ nuke(fd, offset, max_size, 0x00);
+ if (random) {
+ nuke(fd, offset, max_size, 0xaa);
+ nuke(fd, offset, max_size, 0x55);
+ }
+
+ return EX_OK;