diff options
author | jane400 <jane400@postmarketos.org> | 2025-01-15 01:24:20 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2025-01-15 19:33:45 +0100 |
commit | 9e4719902856da41cd1172f9cdb4d50b0407c906 (patch) | |
tree | 73b2b38fbfe81a3f4d7af2e68e1f5e4caac278fc /src | |
parent | mkosi: disable multipathd by default (diff) | |
download | systemd-9e4719902856da41cd1172f9cdb4d50b0407c906.tar.xz systemd-9e4719902856da41cd1172f9cdb4d50b0407c906.zip |
curl-util: use curl_getdate instead of implementing http spec
Available since curl 7.1, which is less than the version required in
meson.build
https://curl.se/libcurl/c/curl_getdate.html
Diffstat (limited to 'src')
-rw-r--r-- | src/import/curl-util.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/import/curl-util.c b/src/import/curl-util.c index 85c4f9b462..efb7e6d7c4 100644 --- a/src/import/curl-util.c +++ b/src/import/curl-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include <errno.h> #include <fcntl.h> #include "alloc-util.h" @@ -385,27 +386,17 @@ int curl_header_strdup(const void *contents, size_t sz, const char *field, char } int curl_parse_http_time(const char *t, usec_t *ret) { - _cleanup_(freelocalep) locale_t loc = (locale_t) 0; - const char *e; - struct tm tm; - assert(t); assert(ret); - loc = newlocale(LC_TIME_MASK, "C", (locale_t) 0); - if (loc == (locale_t) 0) - return -errno; - - /* RFC822 */ - e = strptime_l(t, "%a, %d %b %Y %H:%M:%S %Z", &tm, loc); - if (!e || *e != 0) - /* RFC 850 */ - e = strptime_l(t, "%A, %d-%b-%y %H:%M:%S %Z", &tm, loc); - if (!e || *e != 0) - /* ANSI C */ - e = strptime_l(t, "%a %b %d %H:%M:%S %Y", &tm, loc); - if (!e || *e != 0) + time_t v = curl_getdate(t, NULL); + if (v == (time_t) -1) return -EINVAL; - return mktime_or_timegm_usec(&tm, /* usec= */ true, ret); + if ((usec_t) v >= USEC_INFINITY / USEC_PER_SEC) /* check overflow */ + return -ERANGE; + + *ret = (usec_t) v * USEC_PER_SEC; + + return 0; } |