| 1 |
extern char *strdup (const char *__s) |
| 2 |
__attribute__ ((__nothrow__ , __leaf__, __malloc__, __nonnull__ (1))); |
| 3 |
|
| 4 |
extern void abort (void) |
| 5 |
__attribute__ ((__nothrow__ , __leaf__, __noreturn__)); |
| 6 |
|
| 7 |
extern int getopt (int ___argc, char *const *___argv, const char *__shortopts) |
| 8 |
__attribute__ ((__nothrow__ , __leaf__, __nonnull__ (2, 3))); |
| 9 |
extern char *optarg; |
| 10 |
|
| 11 |
extern void free (void *__ptr) |
| 12 |
__attribute__ ((__nothrow__ , __leaf__)); |
| 13 |
|
| 14 |
struct state { |
| 15 |
const char *confpath; |
| 16 |
const char *host; |
| 17 |
const char *port; |
| 18 |
const char *state_dir_prefix; |
| 19 |
}; |
| 20 |
|
| 21 |
static inline char *xstrdup(const char *s) { |
| 22 |
char *val = strdup(s); |
| 23 |
if (!val) |
| 24 |
abort(); |
| 25 |
return val; |
| 26 |
} |
| 27 |
|
| 28 |
int config_init(struct state *config); |
| 29 |
|
| 30 |
int main(int argc, char *argv[]) { |
| 31 |
struct state state; |
| 32 |
|
| 33 |
config_init(&state); |
| 34 |
|
| 35 |
switch (getopt(argc, argv, "H:p:")) { |
| 36 |
case 'H': |
| 37 |
state.host = xstrdup(optarg); |
| 38 |
break; |
| 39 |
case 'p': |
| 40 |
state.port = xstrdup(optarg); |
| 41 |
break; |
| 42 |
} |
| 43 |
|
| 44 |
free((void*)state.host); |
| 45 |
free((void*)state.port); |
| 46 |
return 0; |
| 47 |
} |