int cmd_create(int argc, char *argv[]) { CgptCreateParams params; memset(¶ms, 0, sizeof(params)); int c; int errorcnt = 0; opterr = 0; // quiet, you while ((c=getopt(argc, argv, ":hz")) != -1) { switch (c) { case 'z': params.zap = 1; break; case 'h': Usage(); return CGPT_OK; case '?': Error("unrecognized option: -%c\n", optopt); errorcnt++; break; case ':': Error("missing argument to -%c\n", optopt); errorcnt++; break; default: errorcnt++; break; } } if (errorcnt) { Usage(); return CGPT_FAILED; } if (optind >= argc) { Usage(); return CGPT_FAILED; } params.drive_name = argv[optind]; return CgptCreate(¶ms); }
int cmd_create(int argc, char *argv[]) { CgptCreateParams params; memset(¶ms, 0, sizeof(params)); int c; int errorcnt = 0; char *e = 0; opterr = 0; // quiet, you while ((c=getopt(argc, argv, ":hcs:zg:")) != -1) { switch (c) { case 'z': params.zap = 1; break; case 'c': params.create = 1; break; case 's': params.min_size = strtoull(optarg, &e, 0); if (!*optarg || (e && *e)) { Error("invalid argument to -%c: \"%s\"\n", c, optarg); errorcnt++; } break; case 'g': params.drive_guid = optarg; break; case 'h': Usage(); return CGPT_OK; case '?': Error("unrecognized option: -%c\n", optopt); errorcnt++; break; case ':': Error("missing argument to -%c\n", optopt); errorcnt++; break; default: errorcnt++; break; } } if (params.create && !params.min_size) { Error("minimum size (-s) is required with create (-c)\n"); errorcnt++; } if (errorcnt) { Usage(); return CGPT_FAILED; } if (optind >= argc) { Usage(); return CGPT_FAILED; } params.drive_name = argv[optind]; return CgptCreate(¶ms); }