Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add long option to apfs-label & apfs-snap #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apfs-label/apfs-label.8
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ is a simple tool that lists the index and label of all volumes in an
APFS container, to help the user decide which one to mount with the driver.
.SH OPTIONS
.TP
.B \-v
.B \-v, \-\-version
Print the version number of
.B apfs-label
and exit.
Expand Down
14 changes: 10 additions & 4 deletions apfs-label/apfs-label.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include <apfs/checksum.h>
#include <apfs/raw.h>
#include "version.h"
Expand Down Expand Up @@ -306,14 +307,18 @@ static void list_labels(void)

int main(int argc, char *argv[])
{
const char *filename = NULL;

if (argc == 0)
exit(1);
progname = argv[0];

static const struct option long_options[] = {
{ .name = "version", .has_arg = no_argument , .flag = NULL, .val = 'v' },
{ 0 },
};

while (1) {
int opt = getopt(argc, argv, "v");
int opt_index = 0;
int opt = getopt_long(argc, argv, "v", long_options, &opt_index);

if (opt == -1)
break;
Expand All @@ -328,7 +333,8 @@ int main(int argc, char *argv[])

if (optind != argc - 1)
usage();
filename = argv[optind];

const char *filename = argv[optind];

dev_fd = open(filename, O_RDONLY);
if (dev_fd == -1)
Expand Down
2 changes: 1 addition & 1 deletion apfs-snap/apfs-snap.8
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The label for the new snapshot must be specified in
.IR name .
.SH OPTIONS
.TP
.B \-v
.B \-v, \-\-version
Print the version number of
.B apfs-snap
and exit.
Expand Down
9 changes: 8 additions & 1 deletion apfs-snap/apfs-snap.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <getopt.h>
#include "version.h"

static char *progname;
Expand Down Expand Up @@ -89,7 +90,13 @@ int main(int argc, char *argv[])
progname = argv[0];

while (1) {
int opt = getopt(argc, argv, "v");
static const struct option long_options[] = {
{ .name = "version", .has_arg = no_argument , .flag = NULL, .val = 'v' },
{ 0 },
};

int opt_index = 0;
int opt = getopt_long(argc, argv, "v", long_options, &opt_index);

if (opt == -1)
break;
Expand Down