uclient-fetch: use package name pattern in message for missing SSL library
[project/uclient.git] / uclient-fetch.c
index 4c603fb..6961d94 100644 (file)
@@ -50,7 +50,7 @@ static bool verify = true;
 static bool proxy = true;
 static bool default_certs = false;
 static bool no_output;
-static const char *output_file;
+static const char *opt_output_file;
 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)
 {
+       const char *output_file = opt_output_file;
        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];
+       ssize_t n;
        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));
-               if (!len)
+               if (len <= 0)
                        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;
        }
 
-       if (output_fd >= 0 && !output_file) {
+       if (output_fd >= 0 && !opt_output_file) {
                close(output_fd);
                output_fd = -1;
        }
@@ -489,7 +494,7 @@ static int no_ssl(const char *progname)
 {
        fprintf(stderr,
                "%s: SSL support not available, please install one of the "
-               "libustream-ssl-* libraries as well as the ca-bundle and "
+               "libustream-.*[ssl|tls] packages as well as the ca-bundle and "
                "ca-certificates packages.\n",
                progname);
 
@@ -611,7 +616,7 @@ int main(int argc, char **argv)
                        user_agent = optarg;
                        break;
                case 'O':
-                       output_file = optarg;
+                       opt_output_file = optarg;
                        break;
                case 'P':
                        if (chdir(optarg)) {
@@ -660,9 +665,11 @@ int main(int argc, char **argv)
        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;
        }