diff options
author | Felix Fietkau <nbd@openwrt.org> | 2016-01-16 19:18:38 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2016-01-16 19:19:29 +0100 |
commit | 5c52f09ef02a07e7c99393a6bb97d956fe3bffe4 (patch) | |
tree | 415e6da898e5fbb023be73ce67afb82e9d13212b | |
parent | 057a89885bb9dc4cf3a6e9dfc4be04ad72c4f8f0 (diff) | |
download | uclient-5c52f09ef02a07e7c99393a6bb97d956fe3bffe4.tar.gz |
uclient-fetch: clean up output file selection
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | uclient-fetch.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/uclient-fetch.c b/uclient-fetch.c index 7418f82..da11268 100644 --- a/uclient-fetch.c +++ b/uclient-fetch.c @@ -58,7 +58,7 @@ static void request_done(struct uclient *cl); static int open_output_file(const char *path, bool create) { - char *filename; + char *filename = NULL; int flags = O_WRONLY; int ret; @@ -66,20 +66,20 @@ static int open_output_file(const char *path, bool create) flags |= O_CREAT | O_EXCL; if (output_file) { - if (!strcmp(output_file, "-")) - return STDOUT_FILENO; - - if (!quiet) - fprintf(stderr, "Writing to stdout\n"); + if (!strcmp(output_file, "-")) { + if (!quiet) + fprintf(stderr, "Writing to stdout\n"); - unlink(output_file); - return open(output_file, flags, 0644); + return STDOUT_FILENO; + } + } else { + filename = uclient_get_url_filename(path, "index.html"); + output_file = filename; } - filename = uclient_get_url_filename(path, "index.html"); if (!quiet) - fprintf(stderr, "Writing to '%s'\n", filename); - ret = open(filename, flags, 0644); + fprintf(stderr, "Writing to '%s'\n", output_file); + ret = open(output_file, flags, 0644); free(filename); return ret; |