diff --git a/locale/tr/LC_MESSAGES/mc.po b/locale/tr/LC_MESSAGES/mc.po index a361b12..b2342a1 100644 --- a/locale/tr/LC_MESSAGES/mc.po +++ b/locale/tr/LC_MESSAGES/mc.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-05-09 23:17+0300\n" +"POT-Creation-Date: 2024-05-09 23:28+0300\n" "PO-Revision-Date: 2024-05-01 13:34+0300\n" "Last-Translator: \n" "Language-Team: Turkish \n" @@ -254,26 +254,30 @@ msgid "Description" msgstr "" #: src/url.c:44 +msgid "Failed to open /dev/null" +msgstr "" + +#: src/url.c:51 msgid "Failed to init curl" msgstr "" -#: src/url.c:55 +#: src/url.c:63 msgid "Request failed" msgstr "" -#: src/url.c:62 +#: src/url.c:70 msgid "Failed to get the response code" msgstr "" -#: src/url.c:68 +#: src/url.c:76 msgid "Response is not a redirect" msgstr "" -#: src/url.c:75 +#: src/url.c:83 msgid "Failed to get the location header" msgstr "" -#: src/url.c:81 +#: src/url.c:89 msgid "Invalid location header" msgstr "" diff --git a/src/error.h b/src/error.h index 83bcd62..096e96f 100644 --- a/src/error.h +++ b/src/error.h @@ -19,12 +19,13 @@ enum ErrorCodes { UrlCurlFail = 940, UrlReqFail = 939, + UrlNullFail = 938, - UrlReqCodeFail = 938, - UrlReqBadCode = 937, + UrlReqCodeFail = 937, + UrlReqBadCode = 936, - UrlLocationFail = 936, - UrlLocationBad = 935 + UrlLocationFail = 935, + UrlLocationBad = 934 }; extern int errno; diff --git a/src/url.c b/src/url.c index 69809d9..5829842 100644 --- a/src/url.c +++ b/src/url.c @@ -36,19 +36,27 @@ char *url_complete(char *name) { char url[strlen(name) + strlen(HUB_URL) + 1]; sprintf(url, "%s/%s", HUB_URL, name); + FILE *devnull = fopen("/dev/null", "w"); char *location = NULL; long code = 0; + if (NULL == devnull) { + error_set(_("Failed to open /dev/null")); + errno = UrlNullFail; + return NULL; + } + CURL *curl = curl_easy_init(); if (NULL == curl) { error_set(_("Failed to init curl")); errno = UrlCurlFail; - return NULL; + goto CLEANUP; } curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl/mp"); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0L); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, devnull); CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { @@ -86,7 +94,9 @@ char *url_complete(char *name) { location = strdup(location); CLEANUP: - curl_easy_cleanup(curl); + fclose(devnull); + if (NULL != curl) + curl_easy_cleanup(curl); return location; }