projects
/
project
/
uclient.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
uclient-fetch: fix overloading of output_file variable
[project/uclient.git]
/
uclient-fetch.c
diff --git
a/uclient-fetch.c
b/uclient-fetch.c
index
4c603fb
..
2e553a0
100644
(file)
--- a/
uclient-fetch.c
+++ b/
uclient-fetch.c
@@
-50,7
+50,7
@@
static bool verify = true;
static bool proxy = true;
static bool default_certs = false;
static bool no_output;
static bool proxy = true;
static bool default_certs = false;
static bool no_output;
-static const char *output_file;
+static const char *o
pt_o
utput_file;
static int output_fd = -1;
static int error_ret;
static off_t out_offset;
static int output_fd = -1;
static int error_ret;
static off_t out_offset;
@@
-97,6
+97,7
@@
get_proxy_url(char *url)
static int open_output_file(const char *path, uint64_t resume_offset)
{
static int open_output_file(const char *path, uint64_t resume_offset)
{
+ const char *output_file = opt_output_file;
char *filename = NULL;
int flags;
int ret;
char *filename = NULL;
int flags;
int ret;
@@
-254,6
+255,7
@@
static void header_done_cb(struct uclient *cl)
static void read_data_cb(struct uclient *cl)
{
char buf[256];
static void read_data_cb(struct uclient *cl)
{
char buf[256];
+ ssize_t n;
int len;
if (!no_output && output_fd < 0)
int len;
if (!no_output && output_fd < 0)
@@
-261,12
+263,15
@@
static void read_data_cb(struct uclient *cl)
while (1) {
len = uclient_read(cl, buf, sizeof(buf));
while (1) {
len = uclient_read(cl, buf, sizeof(buf));
- if (
!len
)
+ if (
len <= 0
)
return;
out_bytes += len;
return;
out_bytes += len;
- if (!no_output)
- write(output_fd, buf, len);
+ if (!no_output) {
+ n = write(output_fd, buf, len);
+ if (n < 0)
+ return;
+ }
}
}
}
}
@@
-363,7
+368,7
@@
static void request_done(struct uclient *cl)
return;
}
return;
}
- if (output_fd >= 0 && !output_file) {
+ if (output_fd >= 0 && !o
pt_o
utput_file) {
close(output_fd);
output_fd = -1;
}
close(output_fd);
output_fd = -1;
}
@@
-611,7
+616,7
@@
int main(int argc, char **argv)
user_agent = optarg;
break;
case 'O':
user_agent = optarg;
break;
case 'O':
- output_file = optarg;
+ o
pt_o
utput_file = optarg;
break;
case 'P':
if (chdir(optarg)) {
break;
case 'P':
if (chdir(optarg)) {
@@
-660,9
+665,11
@@
int main(int argc, char **argv)
uloop_init();
if (username) {
uloop_init();
if (username) {
- if (password)
- asprintf(&auth_str, "%s:%s", username, password);
- else
+ if (password) {
+ rc = asprintf(&auth_str, "%s:%s", username, password);
+ if (rc < 0)
+ return rc;
+ } else
auth_str = username;
}
auth_str = username;
}