Gentoo Archives: gentoo-commits

From: Fabian Groffen <grobian@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage-utils:master commit in: /
Date: Wed, 23 Feb 2022 11:57:12
Message-Id: 1645617355.b59cdb9849c6528922664fcc1c07537ac71e05b1.grobian@gentoo
1 commit: b59cdb9849c6528922664fcc1c07537ac71e05b1
2 Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 23 11:55:55 2022 +0000
4 Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
5 CommitDate: Wed Feb 23 11:55:55 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=b59cdb98
7
8 qlop: fix date parsing of epochs on musl
9
10 %s isn't a valid modifier in POSIX for strptime, so parse the number
11 manually and produce a time out of that.
12
13 Bug: https://bugs.gentoo.org/833942
14 Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
15
16 qlop.c | 12 ++++++------
17 1 file changed, 6 insertions(+), 6 deletions(-)
18
19 diff --git a/qlop.c b/qlop.c
20 index addb4b3..16bf69f 100644
21 --- a/qlop.c
22 +++ b/qlop.c
23 @@ -126,18 +126,18 @@ parse_date(const char *sdate, time_t *t)
24 */
25 size_t len = strspn(sdate, "0123456789-:T@");
26 if (sdate[len] == '\0') {
27 - const char *fmt;
28 if (sdate[0] == '@') {
29 - fmt = "@%s";
30 + time_t d = (time_t)strtoll(&sdate[1], (char **)&s, 10);
31 + localtime_r(&d, &tm);
32 } else if (strchr(sdate, '-') == NULL) {
33 - fmt = "%s";
34 + time_t d = (time_t)strtoll(sdate, (char **)&s, 10);
35 + localtime_r(&d, &tm);
36 } else if ((s = strchr(sdate, 'T')) == NULL) {
37 - fmt = "%Y-%m-%d";
38 + s = strptime(sdate, "%Y-%m-%d", &tm);
39 } else {
40 - fmt = "%Y-%m-%dT%H:%M:%S";
41 + s = strptime(sdate, "%Y-%m-%dT%H:%M:%S", &tm);
42 }
43
44 - s = strptime(sdate, fmt, &tm);
45 if (s == NULL || s[0] != '\0')
46 return false;
47 } else {