diff options
author | William Wennerström <william@wstrm.dev> | 2020-07-21 11:15:48 +0200 |
---|---|---|
committer | William Wennerström <william@wstrm.dev> | 2020-11-16 21:58:09 +0100 |
commit | ab83afe21b1a7d5d2aff5f029687ea659e05360f (patch) | |
tree | 95e07d78727cf587228ae668e9e92213f822297a /src/tools | |
parent | 3d344cfeaa7708b5786e55d18af0cbcfc8ed25ab (diff) | |
download | profani-tty-ab83afe21b1a7d5d2aff5f029687ea659e05360f.tar.gz |
Switch to g_strerror
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/aesgcm_download.c | 32 | ||||
-rw-r--r-- | src/tools/http_download.c | 10 |
2 files changed, 19 insertions, 23 deletions
diff --git a/src/tools/aesgcm_download.c b/src/tools/aesgcm_download.c index 6b60ba08..d6a85d06 100644 --- a/src/tools/aesgcm_download.c +++ b/src/tools/aesgcm_download.c @@ -68,9 +68,6 @@ aesgcm_file_get(void* userdata) char* https_url = NULL; char* fragment = NULL; - const size_t err_len = 100; - char err_buf[err_len]; - if (omemo_parse_aesgcm_url(aesgcm_dl->url, &https_url, &fragment) != 0) { http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Download failed: Cannot parse URL '%s'.", @@ -78,24 +75,29 @@ aesgcm_file_get(void* userdata) return NULL; } - char* tmpname = NULL; - if (g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL) == -1) { - strerror_r(errno, err_buf, err_len); + gchar* tmpname = NULL; + gint tmpfd; + if ((tmpfd = g_file_open_tmp("profanity.XXXXXX", &tmpname, NULL)) == -1) { http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Downloading '%s' failed: Unable to create " "temporary ciphertext file for writing " "(%s).", - https_url, err_buf); + https_url, g_strerror(errno)); return NULL; + } else { + // TODO(wstrm): Maybe refactor this to use file handles so we do not + // have to open a dummy file descriptor and then close it. + // It's pretty ugly this way... + close(tmpfd); } FILE* outfh = fopen(aesgcm_dl->filename, "wb"); if (outfh == NULL) { - strerror_r(errno, err_buf, err_len); http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Downloading '%s' failed: Unable to open " "output file at '%s' for writing (%s).", - https_url, aesgcm_dl->filename, err_buf); + https_url, aesgcm_dl->filename, + g_strerror(errno)); return NULL; } @@ -111,11 +113,11 @@ aesgcm_file_get(void* userdata) FILE* tmpfh = fopen(tmpname, "rb"); if (tmpfh == NULL) { - strerror_r(errno, err_buf, err_len); http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, "Downloading '%s' failed: Unable to open " "temporary file at '%s' for reading (%s).", - aesgcm_dl->url, aesgcm_dl->filename, err_buf); + aesgcm_dl->url, aesgcm_dl->filename, + g_strerror(errno)); return NULL; } @@ -124,12 +126,11 @@ aesgcm_file_get(void* userdata) http_dl->bytes_received, fragment); if (fclose(tmpfh) == EOF) { - strerror_r(errno, err_buf, err_len); - cons_show_error(err_buf); + cons_show_error(g_strerror(errno)); } remove(tmpname); - free(tmpname); + g_free(tmpname); if (crypt_res != GPG_ERR_NO_ERROR) { http_print_transfer_update(aesgcm_dl->window, aesgcm_dl->url, @@ -139,8 +140,7 @@ aesgcm_file_get(void* userdata) } if (fclose(outfh) == EOF) { - strerror_r(errno, err_buf, err_len); - cons_show_error(err_buf); + cons_show_error(g_strerror(errno)); } free(https_url); diff --git a/src/tools/http_download.c b/src/tools/http_download.c index a470feec..d14ab0e8 100644 --- a/src/tools/http_download.c +++ b/src/tools/http_download.c @@ -103,9 +103,6 @@ http_file_get(void* userdata) { HTTPDownload* download = (HTTPDownload*)userdata; - const size_t err_len = 100; - char err_buf[err_len]; - char* err = NULL; CURL* curl; @@ -120,11 +117,11 @@ http_file_get(void* userdata) FILE* outfh = fopen(download->filename, "wb"); if (outfh == NULL) { - strerror_r(errno, err_buf, err_len); http_print_transfer_update(download->window, download->url, "Downloading '%s' failed: Unable to open " "output file at '%s' for writing (%s).", - download->url, download->filename, err_buf); + download->url, download->filename, + g_strerror(errno)); return NULL; } @@ -161,8 +158,7 @@ http_file_get(void* userdata) curl_global_cleanup(); if (fclose(outfh) == EOF) { - strerror_r(errno, err_buf, err_len); - err = strdup(err_buf); + err = strdup(g_strerror(errno)); } pthread_mutex_lock(&lock); |