int main(int argc, char* argv[])
{
- char** pp;
+ int opt;
const char* spec = NULL;
bool sb_only = false;
bool used_sectors = false;
printf("dumpexfat %u.%u.%u\n",
EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
- for (pp = argv + 1; *pp; pp++)
+ while ((opt = getopt(argc, argv, "suV")) != -1)
{
- if (strcmp(*pp, "-s") == 0)
+ switch (opt)
+ {
+ case 's':
sb_only = true;
- else if (strcmp(*pp, "-u") == 0)
+ break;
+ case 'u':
used_sectors = true;
- else if (strcmp(*pp, "-V") == 0)
- {
+ break;
+ case 'V':
puts("Copyright (C) 2011-2013 Andrew Nayenko");
return 0;
- }
- else if (spec == NULL)
- spec = *pp;
- else
+ default:
usage(argv[0]);
+ }
}
- if (spec == NULL)
+ if (argc - optind != 1)
usage(argv[0]);
+ spec = argv[optind];
if (sb_only)
return dump_sb(spec);
#include <exfat.h>
#include <exfatfs.h>
#include <inttypes.h>
+#include <unistd.h>
#define exfat_debug(format, ...)
int main(int argc, char* argv[])
{
- char** pp;
+ int opt;
const char* spec = NULL;
struct exfat ef;
printf("exfatfsck %u.%u.%u\n",
EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
- for (pp = argv + 1; *pp; pp++)
+ while ((opt = getopt(argc, argv, "V")) != -1)
{
- if (strcmp(*pp, "-V") == 0)
+ switch (opt)
{
+ case 'V':
puts("Copyright (C) 2011-2013 Andrew Nayenko");
return 0;
- }
- else if (spec == NULL)
- spec = *pp;
- else
+ default:
usage(argv[0]);
+ break;
+ }
}
- if (spec == NULL)
+ if (argc - optind != 1)
usage(argv[0]);
+ spec = argv[optind];
if (exfat_mount(&ef, spec, "ro") != 0)
return 1;
int debug = 0;
struct fuse_chan* fc = NULL;
struct fuse* fh = NULL;
- char** pp;
+ int opt;
printf("FUSE exfat %u.%u.%u\n",
EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
return 1;
}
- for (pp = argv + 1; *pp; pp++)
+ while ((opt = getopt(argc, argv, "dno:V")) != -1)
{
- if (strcmp(*pp, "-o") == 0)
+ switch (opt)
{
- pp++;
- if (*pp == NULL)
- usage(argv[0]);
- mount_options = add_option(mount_options, *pp, NULL);
+ case 'd':
+ debug = 1;
+ break;
+ case 'n':
+ break;
+ case 'o':
+ mount_options = add_option(mount_options, optarg, NULL);
if (mount_options == NULL)
return 1;
- }
- else if (strcmp(*pp, "-d") == 0)
- debug = 1;
- else if (strcmp(*pp, "-V") == 0)
- {
+ break;
+ case 'V':
free(mount_options);
puts("Copyright (C) 2010-2013 Andrew Nayenko");
return 0;
- }
- else if (strcmp(*pp, "-n") == 0)
- /* ignore */ ;
- else if (spec == NULL)
- spec = *pp;
- else if (mount_point == NULL)
- mount_point = *pp;
- else
- {
+ default:
free(mount_options);
usage(argv[0]);
+ break;
}
}
- if (spec == NULL || mount_point == NULL)
+ if (argc - optind != 2)
{
free(mount_options);
usage(argv[0]);
}
+ spec = argv[optind];
+ mount_point = argv[optind + 1];
if (exfat_mount(&ef, spec, mount_options) != 0)
{
int main(int argc, char* argv[])
{
const char* spec = NULL;
- char** pp;
+ int opt;
int spc_bits = -1;
const char* volume_label = NULL;
uint32_t volume_serial = 0;
printf("mkexfatfs %u.%u.%u\n",
EXFAT_VERSION_MAJOR, EXFAT_VERSION_MINOR, EXFAT_VERSION_PATCH);
- for (pp = argv + 1; *pp; pp++)
+ while ((opt = getopt(argc, argv, "i:n:p:s:V")) != -1)
{
- if (strcmp(*pp, "-s") == 0)
+ switch (opt)
{
- pp++;
- if (*pp == NULL)
- usage(argv[0]);
- spc_bits = logarithm2(atoi(*pp));
+ case 'i':
+ volume_serial = strtol(optarg, NULL, 16);
+ break;
+ case 'n':
+ volume_label = optarg;
+ break;
+ case 'p':
+ first_sector = strtoll(optarg, NULL, 10);
+ break;
+ case 's':
+ spc_bits = logarithm2(atoi(optarg));
if (spc_bits < 0)
{
- exfat_error("invalid option value: `%s'", *pp);
+ exfat_error("invalid option value: `%s'", optarg);
return 1;
}
- }
- else if (strcmp(*pp, "-n") == 0)
- {
- pp++;
- if (*pp == NULL)
- usage(argv[0]);
- volume_label = *pp;
- }
- else if (strcmp(*pp, "-i") == 0)
- {
- pp++;
- if (*pp == NULL)
- usage(argv[0]);
- volume_serial = strtol(*pp, NULL, 16);
- }
- else if (strcmp(*pp, "-p") == 0)
- {
- pp++;
- if (*pp == NULL)
- usage(argv[0]);
- first_sector = strtoll(*pp, NULL, 10);
- }
- else if (strcmp(*pp, "-V") == 0)
- {
+ break;
+ case 'V':
puts("Copyright (C) 2011-2013 Andrew Nayenko");
return 0;
- }
- else if (spec == NULL)
- spec = *pp;
- else
+ default:
usage(argv[0]);
+ break;
+ }
}
- if (spec == NULL)
+ if (argc - optind != 1)
usage(argv[0]);
+ spec = argv[optind];
dev = exfat_open(spec, EXFAT_MODE_RW);
if (dev == NULL)