-
Notifications
You must be signed in to change notification settings - Fork 2
/
opts.c
56 lines (54 loc) · 1.28 KB
/
opts.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "banned.h"
#include "logger.h"
#include "opts.h"
#include "vec.h"
int cape_parse_opts(
int argc,
char *const *const argv,
struct cape_opts *opts, /* out */
struct cape_string_vec *env /* out */
) {
int c;
int err = 0;
while ((c = getopt(argc, argv, "e:Ihr:u:d:n")) != -1) {
switch (c) {
case 'h':
cape_print_usage();
exit(EXIT_SUCCESS);
case 'n':
opts->disable_networking = true;
break;
case 'd':
opts->directory = optarg;
break;
case 'e':
err = cape_string_vec_push(env, optarg);
if (err) {
cape_log_error("could not push environment variable");
cape_string_vec_free(env);
return -1;
}
break;
case 'r':
opts->root = optarg;
break;
case 'u':
opts->user = optarg;
break;
case 'I':
opts->insecure_mode = true;
break;
default:
return -1;
}
}
if (optind >= argc) {
cape_log_error("no program specified");
return -1;
} else {
return optind;
}
}