#include <stdlib.h>
#include <string.h>
+#include "volumes.h"
#include "crc32c.h"
#include "commands.h"
#include "utils.h"
return strncmp(str, prefix, len) ? NULL : str + len;
}
-int prefixcmp(const char *str, const char *prefix)
-{
- for (; ; str++, prefix++)
- if (!*prefix)
- return 0;
- else if (*str != *prefix)
- return (unsigned char)*prefix - (unsigned char)*str;
-}
-
static int parse_one_token(const char *arg, const struct cmd_group *grp,
const struct cmd_struct **cmd_ret)
{
return 0;
}
-static void handle_options(int *argc, char ***argv)
+static void check_options(int argc, char **argv)
{
- if (*argc > 0) {
- const char *arg = (*argv)[0];
- if (arg[0] != '-' ||
- !strcmp(arg, "--help") ||
- !strcmp(arg, "--version"))
- return;
- fprintf(stderr, "Unknown option: %s\n", arg);
- fprintf(stderr, "usage: %s\n",
- btrfs_cmd_group.usagestr[0]);
- exit(129);
- }
- return;
+ const char *arg;
+
+ if (argc == 0)
+ return;
+
+ arg = argv[0];
+
+ if (arg[0] != '-' ||
+ !strcmp(arg, "--help") ||
+ !strcmp(arg, "--version"))
+ return;
+
+ fprintf(stderr, "Unknown option: %s\n", arg);
+ fprintf(stderr, "usage: %s\n",
+ btrfs_cmd_group.usagestr[0]);
+ exit(129);
}
static const struct cmd_group btrfs_cmd_group = {
{
const struct cmd_struct *cmd;
const char *bname;
+ int ret;
if ((bname = strrchr(argv[0], '/')) != NULL)
bname++;
} else {
argc--;
argv++;
- handle_options(&argc, &argv);
+ check_options(argc, argv);
if (argc > 0) {
if (!prefixcmp(argv[0], "--"))
argv[0] += 2;
} else {
- usage_command_group(&btrfs_cmd_group, 0, 0);
+ usage_command_group_short(&btrfs_cmd_group);
exit(1);
}
}
crc32c_optimization_init();
fixup_argv0(argv, cmd->token);
- exit(cmd->fn(argc, argv));
+
+ ret = cmd->fn(argc, argv);
+
+ btrfs_close_all_devices();
+
+ exit(ret);
}