Resolves: RHEL-108555,RHEL-108568,RHEL-108576,RHEL-108584,RHEL-108596,RHEL-108598,RHEL-109096,RHEL-109488,RHEL-111065,RHEL-31756,RHEL-50103
317 lines
11 KiB
Diff
317 lines
11 KiB
Diff
From 753dd2e5f28a9b5a552efda75bcbec20ad501e69 Mon Sep 17 00:00:00 2001
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
|
Date: Tue, 14 Feb 2023 02:04:31 +0900
|
|
Subject: [PATCH] time-util: rename variables
|
|
|
|
(cherry picked from commit cf98b66d1ad0ff0e9ee0444861069ebade038dbb)
|
|
|
|
Related: RHEL-109488
|
|
---
|
|
src/basic/time-util.c | 86 +++++++++++++++++++++----------------------
|
|
src/basic/time-util.h | 16 ++++----
|
|
2 files changed, 51 insertions(+), 51 deletions(-)
|
|
|
|
diff --git a/src/basic/time-util.c b/src/basic/time-util.c
|
|
index 404fde01db..7dbd3af20a 100644
|
|
--- a/src/basic/time-util.c
|
|
+++ b/src/basic/time-util.c
|
|
@@ -604,7 +604,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
|
|
return buf;
|
|
}
|
|
|
|
-static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) {
|
|
+static int parse_timestamp_impl(const char *t, usec_t *ret, bool with_tz) {
|
|
static const struct {
|
|
const char *name;
|
|
const int nr;
|
|
@@ -628,7 +628,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) {
|
|
const char *k, *utc = NULL, *tzn = NULL;
|
|
struct tm tm, copy;
|
|
time_t x;
|
|
- usec_t x_usec, plus = 0, minus = 0, ret;
|
|
+ usec_t usec, x_usec, plus = 0, minus = 0;
|
|
int r, weekday = -1, dst = -1;
|
|
size_t i;
|
|
|
|
@@ -651,9 +651,9 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) {
|
|
assert(t);
|
|
|
|
if (t[0] == '@' && !with_tz)
|
|
- return parse_sec(t + 1, usec);
|
|
+ return parse_sec(t + 1, ret);
|
|
|
|
- ret = now(CLOCK_REALTIME);
|
|
+ usec = now(CLOCK_REALTIME);
|
|
|
|
if (!with_tz) {
|
|
if (streq(t, "now"))
|
|
@@ -734,7 +734,7 @@ static int parse_timestamp_impl(const char *t, usec_t *usec, bool with_tz) {
|
|
}
|
|
}
|
|
|
|
- x = (time_t) (ret / USEC_PER_SEC);
|
|
+ x = (time_t) (usec / USEC_PER_SEC);
|
|
x_usec = 0;
|
|
|
|
if (!localtime_or_gmtime_r(&x, &tm, utc))
|
|
@@ -871,24 +871,24 @@ from_tm:
|
|
if (x < 0)
|
|
return -EINVAL;
|
|
|
|
- ret = (usec_t) x * USEC_PER_SEC + x_usec;
|
|
- if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
+ usec = (usec_t) x * USEC_PER_SEC + x_usec;
|
|
+ if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
return -EINVAL;
|
|
|
|
finish:
|
|
- if (ret + plus < ret) /* overflow? */
|
|
+ if (usec + plus < usec) /* overflow? */
|
|
return -EINVAL;
|
|
- ret += plus;
|
|
- if (ret > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
+ usec += plus;
|
|
+ if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
|
return -EINVAL;
|
|
|
|
- if (ret >= minus)
|
|
- ret -= minus;
|
|
+ if (usec >= minus)
|
|
+ usec -= minus;
|
|
else
|
|
return -EINVAL;
|
|
|
|
- if (usec)
|
|
- *usec = ret;
|
|
+ if (ret)
|
|
+ *ret = usec;
|
|
return 0;
|
|
}
|
|
|
|
@@ -897,7 +897,7 @@ typedef struct ParseTimestampResult {
|
|
int return_value;
|
|
} ParseTimestampResult;
|
|
|
|
-int parse_timestamp(const char *t, usec_t *usec) {
|
|
+int parse_timestamp(const char *t, usec_t *ret) {
|
|
char *last_space, *tz = NULL;
|
|
ParseTimestampResult *shared, tmp;
|
|
int r;
|
|
@@ -907,7 +907,7 @@ int parse_timestamp(const char *t, usec_t *usec) {
|
|
tz = last_space + 1;
|
|
|
|
if (!tz || endswith_no_case(t, " UTC"))
|
|
- return parse_timestamp_impl(t, usec, false);
|
|
+ return parse_timestamp_impl(t, ret, false);
|
|
|
|
shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);
|
|
if (shared == MAP_FAILED)
|
|
@@ -949,13 +949,13 @@ int parse_timestamp(const char *t, usec_t *usec) {
|
|
if (munmap(shared, sizeof *shared) != 0)
|
|
return negative_errno();
|
|
|
|
- if (tmp.return_value == 0 && usec)
|
|
- *usec = tmp.usec;
|
|
+ if (tmp.return_value == 0 && ret)
|
|
+ *ret = tmp.usec;
|
|
|
|
return tmp.return_value;
|
|
}
|
|
|
|
-static const char* extract_multiplier(const char *p, usec_t *multiplier) {
|
|
+static const char* extract_multiplier(const char *p, usec_t *ret) {
|
|
static const struct {
|
|
const char *suffix;
|
|
usec_t usec;
|
|
@@ -996,7 +996,7 @@ static const char* extract_multiplier(const char *p, usec_t *multiplier) {
|
|
|
|
e = startswith(p, table[i].suffix);
|
|
if (e) {
|
|
- *multiplier = table[i].usec;
|
|
+ *ret = table[i].usec;
|
|
return e;
|
|
}
|
|
}
|
|
@@ -1004,9 +1004,9 @@ static const char* extract_multiplier(const char *p, usec_t *multiplier) {
|
|
return p;
|
|
}
|
|
|
|
-int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
|
|
+int parse_time(const char *t, usec_t *ret, usec_t default_unit) {
|
|
const char *p, *s;
|
|
- usec_t r = 0;
|
|
+ usec_t usec = 0;
|
|
bool something = false;
|
|
|
|
assert(t);
|
|
@@ -1021,8 +1021,8 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
|
|
if (*s != 0)
|
|
return -EINVAL;
|
|
|
|
- if (usec)
|
|
- *usec = USEC_INFINITY;
|
|
+ if (ret)
|
|
+ *ret = USEC_INFINITY;
|
|
return 0;
|
|
}
|
|
|
|
@@ -1069,10 +1069,10 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
|
|
return -ERANGE;
|
|
|
|
k = (usec_t) l * multiplier;
|
|
- if (k >= USEC_INFINITY - r)
|
|
+ if (k >= USEC_INFINITY - usec)
|
|
return -ERANGE;
|
|
|
|
- r += k;
|
|
+ usec += k;
|
|
|
|
something = true;
|
|
|
|
@@ -1082,10 +1082,10 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
|
|
|
|
for (b = e + 1; *b >= '0' && *b <= '9'; b++, m /= 10) {
|
|
k = (usec_t) (*b - '0') * m;
|
|
- if (k >= USEC_INFINITY - r)
|
|
+ if (k >= USEC_INFINITY - usec)
|
|
return -ERANGE;
|
|
|
|
- r += k;
|
|
+ usec += k;
|
|
}
|
|
|
|
/* Don't allow "0.-0", "3.+1", "3. 1", "3.sec" or "3.hoge" */
|
|
@@ -1094,13 +1094,13 @@ int parse_time(const char *t, usec_t *usec, usec_t default_unit) {
|
|
}
|
|
}
|
|
|
|
- if (usec)
|
|
- *usec = r;
|
|
+ if (ret)
|
|
+ *ret = usec;
|
|
return 0;
|
|
}
|
|
|
|
-int parse_sec(const char *t, usec_t *usec) {
|
|
- return parse_time(t, usec, USEC_PER_SEC);
|
|
+int parse_sec(const char *t, usec_t *ret) {
|
|
+ return parse_time(t, ret, USEC_PER_SEC);
|
|
}
|
|
|
|
int parse_sec_fix_0(const char *t, usec_t *ret) {
|
|
@@ -1127,7 +1127,7 @@ int parse_sec_def_infinity(const char *t, usec_t *ret) {
|
|
return parse_sec(t, ret);
|
|
}
|
|
|
|
-static const char* extract_nsec_multiplier(const char *p, nsec_t *multiplier) {
|
|
+static const char* extract_nsec_multiplier(const char *p, nsec_t *ret) {
|
|
static const struct {
|
|
const char *suffix;
|
|
nsec_t nsec;
|
|
@@ -1172,7 +1172,7 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *multiplier) {
|
|
|
|
e = startswith(p, table[i].suffix);
|
|
if (e) {
|
|
- *multiplier = table[i].nsec;
|
|
+ *ret = table[i].nsec;
|
|
return e;
|
|
}
|
|
}
|
|
@@ -1180,13 +1180,13 @@ static const char* extract_nsec_multiplier(const char *p, nsec_t *multiplier) {
|
|
return p;
|
|
}
|
|
|
|
-int parse_nsec(const char *t, nsec_t *nsec) {
|
|
+int parse_nsec(const char *t, nsec_t *ret) {
|
|
const char *p, *s;
|
|
- nsec_t r = 0;
|
|
+ nsec_t nsec = 0;
|
|
bool something = false;
|
|
|
|
assert(t);
|
|
- assert(nsec);
|
|
+ assert(ret);
|
|
|
|
p = t;
|
|
|
|
@@ -1197,7 +1197,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
|
|
if (*s != 0)
|
|
return -EINVAL;
|
|
|
|
- *nsec = NSEC_INFINITY;
|
|
+ *ret = NSEC_INFINITY;
|
|
return 0;
|
|
}
|
|
|
|
@@ -1244,10 +1244,10 @@ int parse_nsec(const char *t, nsec_t *nsec) {
|
|
return -ERANGE;
|
|
|
|
k = (nsec_t) l * multiplier;
|
|
- if (k >= NSEC_INFINITY - r)
|
|
+ if (k >= NSEC_INFINITY - nsec)
|
|
return -ERANGE;
|
|
|
|
- r += k;
|
|
+ nsec += k;
|
|
|
|
something = true;
|
|
|
|
@@ -1257,10 +1257,10 @@ int parse_nsec(const char *t, nsec_t *nsec) {
|
|
|
|
for (b = e + 1; *b >= '0' && *b <= '9'; b++, m /= 10) {
|
|
k = (nsec_t) (*b - '0') * m;
|
|
- if (k >= NSEC_INFINITY - r)
|
|
+ if (k >= NSEC_INFINITY - nsec)
|
|
return -ERANGE;
|
|
|
|
- r += k;
|
|
+ nsec += k;
|
|
}
|
|
|
|
/* Don't allow "0.-0", "3.+1", "3. 1", "3.sec" or "3.hoge" */
|
|
@@ -1269,7 +1269,7 @@ int parse_nsec(const char *t, nsec_t *nsec) {
|
|
}
|
|
}
|
|
|
|
- *nsec = r;
|
|
+ *ret = nsec;
|
|
|
|
return 0;
|
|
}
|
|
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
|
|
index c98f95a530..9d44cac747 100644
|
|
--- a/src/basic/time-util.h
|
|
+++ b/src/basic/time-util.h
|
|
@@ -141,15 +141,15 @@ static inline char* format_timestamp(char *buf, size_t l, usec_t t) {
|
|
#define FORMAT_TIMESTAMP_STYLE(t, style) \
|
|
format_timestamp_style((char[FORMAT_TIMESTAMP_MAX]){}, FORMAT_TIMESTAMP_MAX, t, style)
|
|
|
|
-int parse_timestamp(const char *t, usec_t *usec);
|
|
+int parse_timestamp(const char *t, usec_t *ret);
|
|
|
|
-int parse_sec(const char *t, usec_t *usec);
|
|
-int parse_sec_fix_0(const char *t, usec_t *usec);
|
|
-int parse_sec_def_infinity(const char *t, usec_t *usec);
|
|
-int parse_time(const char *t, usec_t *usec, usec_t default_unit);
|
|
-int parse_nsec(const char *t, nsec_t *nsec);
|
|
+int parse_sec(const char *t, usec_t *ret);
|
|
+int parse_sec_fix_0(const char *t, usec_t *ret);
|
|
+int parse_sec_def_infinity(const char *t, usec_t *ret);
|
|
+int parse_time(const char *t, usec_t *ret, usec_t default_unit);
|
|
+int parse_nsec(const char *t, nsec_t *ret);
|
|
|
|
-int get_timezones(char ***l);
|
|
+int get_timezones(char ***ret);
|
|
int verify_timezone(const char *name, int log_level);
|
|
static inline bool timezone_is_valid(const char *name, int log_level) {
|
|
return verify_timezone(name, log_level) >= 0;
|
|
@@ -159,7 +159,7 @@ bool clock_supported(clockid_t clock);
|
|
|
|
usec_t usec_shift_clock(usec_t, clockid_t from, clockid_t to);
|
|
|
|
-int get_timezone(char **timezone);
|
|
+int get_timezone(char **ret);
|
|
|
|
time_t mktime_or_timegm(struct tm *tm, bool utc);
|
|
struct tm *localtime_or_gmtime_r(const time_t *t, struct tm *tm, bool utc);
|