gentoo-overlay/sys-apps/systemd/files/0022-Port-to-musl-strptime....

91 lines
4.1 KiB
Diff
Raw Normal View History

From 3c9ab22f9323726710b931ed478e6d5dd81dca2e Mon Sep 17 00:00:00 2001
From: "A. Wilcox" <AWilcox@Wilcox-Tech.com>
Date: Sun, 18 Aug 2024 03:09:47 -0500
Subject: [PATCH 22/34] Port to musl strptime
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
This cannot be upstreamed.
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
---
src/basic/time-util.c | 25 ++++++++++++++++++++-----
src/import/curl-util.c | 6 +++---
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
index b94f37c31c31..1200833a88c5 100644
--- a/src/basic/time-util.c
+++ b/src/basic/time-util.c
@@ -915,6 +915,7 @@ parse_usec:
from_tm:
assert(plus == 0);
assert(minus == 0);
+ tm.tm_wday = weekday;
if (weekday >= 0 && tm.tm_wday != weekday)
return -EINVAL;
@@ -1003,9 +1004,12 @@ int parse_timestamp(const char *t, usec_t *ret) {
return parse_timestamp_impl(t, t_len - 1, /* utc = */ true, /* isdst = */ -1, /* gmtoff = */ 0, ret);
if (t_len > 7 && IN_SET(t[t_len - 6], '+', '-') && t[t_len - 7] != ' ') { /* RFC3339-style welded offset: "1990-12-31T15:59:60-08:00" */
- k = strptime(&t[t_len - 6], "%z", &tm);
- if (k && *k == '\0')
+ k = strptime(&t[t_len - 5], "%R", &tm);
+ if (k && *k == '\0') {
+ tm.tm_gmtoff = ((tm.tm_hour * 60) + tm.tm_min) * 60;
+ if (t[t_len - 6] == '-') tm.tm_gmtoff *= -1;
return parse_timestamp_impl(t, t_len - 6, /* utc = */ true, /* isdst = */ -1, /* gmtoff = */ tm.tm_gmtoff, ret);
+ }
}
tz = strrchr(t, ' ');
@@ -1022,9 +1026,20 @@ int parse_timestamp(const char *t, usec_t *ret) {
/* If the timezone is compatible with RFC-822/ISO 8601 (e.g. +06, or -03:00) then parse the string as
* UTC and shift the result. Note, this must be earlier than the timezone check with tzname[], as
* tzname[] may be in the same format. */
- k = strptime(tz, "%z", &tm);
- if (k && *k == '\0')
- return parse_timestamp_impl(t, max_len, /* utc = */ true, /* isdst = */ -1, /* gmtoff = */ tm.tm_gmtoff, ret);
+ if (*tz == '+' || *tz == '-') {
+ k = strptime(tz+1, "%R", &tm);
+ if (k && *k == '\0') {
+ tm.tm_gmtoff = ((tm.tm_hour * 60) + tm.tm_min) * 60;
+ if (*tz == '-') tm.tm_gmtoff *= -1;
+ return parse_timestamp_impl(t, max_len, /* utc = */ true, /* isdst = */ -1, /* gmtoff = */ tm.tm_gmtoff, ret);
+ }
+ k = strptime(tz+1, "%H", &tm);
+ if (k && *k == '\0') {
+ tm.tm_gmtoff = tm.tm_hour * 3600;
+ if (*tz == '-') tm.tm_gmtoff *= -1;
+ return parse_timestamp_impl(t, max_len, /* utc = */ true, /* isdst = */ -1, /* gmtoff = */ tm.tm_gmtoff, ret);
+ }
+ }
/* If the last word is not a timezone file (e.g. Asia/Tokyo), then let's check if it matches
* tzname[] of the local timezone, e.g. JST or CEST. */
diff --git a/src/import/curl-util.c b/src/import/curl-util.c
index 1628f833a970..4a3003b3e848 100644
--- a/src/import/curl-util.c
+++ b/src/import/curl-util.c
@@ -396,13 +396,13 @@ int curl_parse_http_time(const char *t, usec_t *ret) {
return -errno;
/* RFC822 */
- e = strptime_l(t, "%a, %d %b %Y %H:%M:%S %Z", &tm, loc);
+ e = strptime(t, "%a, %d %b %Y %H:%M:%S %Z", &tm);
if (!e || *e != 0)
/* RFC 850 */
- e = strptime_l(t, "%A, %d-%b-%y %H:%M:%S %Z", &tm, loc);
+ e = strptime(t, "%A, %d-%b-%y %H:%M:%S %Z", &tm);
if (!e || *e != 0)
/* ANSI C */
- e = strptime_l(t, "%a %b %d %H:%M:%S %Y", &tm, loc);
+ e = strptime(t, "%a %b %d %H:%M:%S %Y", &tm);
if (!e || *e != 0)
return -EINVAL;
--
2.41.0