diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-03 01:33:06 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-04-03 01:33:06 +0200 |
commit | 053e3f630a1a90fbb977db307b84e4bf7fb23a96 (patch) | |
tree | f5f30988b6e62e3393c61565f48e4781d8acfbd8 /src | |
parent | bd8dcb97354bc29050e5aefe957c651bf2fedd07 (diff) | |
download | fastd-053e3f630a1a90fbb977db307b84e4bf7fb23a96.tar fastd-053e3f630a1a90fbb977db307b84e4bf7fb23a96.zip |
Only handle - as stdin when given on command line
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/src/config.c b/src/config.c index 7c1b62f..3f18ea0 100644 --- a/src/config.c +++ b/src/config.c @@ -148,10 +148,8 @@ void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filen if (depth >= MAX_CONFIG_DEPTH) exit_error(ctx, "maximum config include depth exceeded"); - bool use_stdin = !strcmp(filename, "-"); - FILE *file; - if (use_stdin) { + if (!filename) { file = stdin; } else { @@ -162,11 +160,17 @@ void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filen char *oldcwd = get_current_dir_name(); - char *filename2 = strdup(filename); - char *dir = dirname(filename2); - if (chdir(dir)) - exit_error(ctx, "change from directory `%s' to `%s' failed", oldcwd, dir); + char *filename2 = NULL; + char *dir = NULL; + + if (filename) { + filename2 = strdup(filename); + dir = dirname(filename2); + + if (chdir(dir)) + exit_error(ctx, "change from directory `%s' to `%s' failed", oldcwd, dir); + } yyscan_t scanner; fastd_config_yylex_init(&scanner); @@ -207,7 +211,7 @@ void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filen free(filename2); free(oldcwd); - if (!use_stdin) + if (filename) fclose(file); } @@ -254,7 +258,10 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con } IF_OPTION_ARG("-c", "--config") { - fastd_read_config(ctx, conf, arg, false, 0); + if (!strcmp(arg, "-")) + fastd_read_config(ctx, conf, NULL, false, 0); + else + fastd_read_config(ctx, conf, arg, false, 0); continue; } |