-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-args.c
More file actions
31 lines (28 loc) · 1.01 KB
/
parse-args.c
File metadata and controls
31 lines (28 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <unistd.h>
int
parse_args(int argc, char *argv[], char **outfname)
{
int opt;
char *optstring = "+o:h";
while ((opt = getopt(argc, argv, optstring)) != -1) {
switch (opt) {
case 'o':
*outfname = optarg;
break;
case 'h':
printf("USAGE: ./mem-dump [-h] [-o OUTPUT-FILENAME] PROC [ARGS...]\n");
printf("\n");
printf("When no output filename specified, use \"mem.dump\" as the default value.\n");
printf("\n");
printf("Examples:\n");
printf(" ./mem-dump echo nice Load and dump /usr/bin/echo binary\n");
printf(" with \"nice\" as the argument\n");
printf(" ./mem-dump ./mem-dump Load and dump ./mem-dump binary\n");
printf(" with no arguments\n");
exit(1);
default:
fprintf(stderr, "?? getopt returned character code 0%o ??\n", opt);
}
}
return optind;
}