aboutsummaryrefslogtreecommitdiff
path: root/src/options.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/options.c')
-rw-r--r--src/options.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/options.c b/src/options.c
index b9cd4f1..be30e7c 100644
--- a/src/options.c
+++ b/src/options.c
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -8,7 +12,8 @@
#include "options.h"
typedef enum opt_type {
- OT_INVALID = 0, OT_NOARG, OT_L, OT_LL, OT_STR
+ OT_INVALID = 0, OT_NOARG, OT_L, OT_LL, OT_STR,
+ OT_PATH
} opt_type;
typedef union opt_ptr {
@@ -32,13 +37,11 @@ struct opt {
#define OPT(type, def_value, is_list, arg, short_help, help) \
{ type, {0}, {def_value}, 0, is_list, arg, short_help, help }
-#define OPT_STR(def_value, is_list, arg, short_help, help) \
- OPT(OT_STR, .str = def_value, is_list, arg, short_help, help)
#define OPT_NOARG(arg, short_help, help) \
OPT(OT_NOARG, .ll = 0, 0, arg, short_help, help)
static struct opt options[OPT_MAX+1] = {
- OPT_STR("./potd.log", 0, "log", "short help", "help"),
- OPT_STR(NULL, 0, "log-level", "short help", "help"),
+ OPT(OT_PATH, .str = POTD_LOGFILE, 0, "log-file", "short help", "help"),
+ OPT(OT_STR, .ll = 0, 0, "log-level", "short help", "help"),
OPT_NOARG("daemon", "short help", "help"),
OPT(OT_INVALID, .ll = 0, 0, NULL, NULL, NULL)
@@ -67,6 +70,9 @@ static int setopt(struct opt *o, const char *optarg)
case OT_STR:
o->value.str_dup = strdup(optarg);
break;
+ case OT_PATH:
+ o->value.str_dup = realpath(optarg, NULL);
+ break;
case OT_NOARG:
case OT_INVALID:
return 1;
@@ -135,7 +141,8 @@ getopt_str(opt_name on)
{
char *str;
- assert(options[on].type == OT_STR);
+ assert(options[on].type == OT_STR ||
+ options[on].type == OT_PATH);
assert(getopt_used(on) || options[on].def_value.str);
str = options[on].value.str_dup;
if (!str)