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;
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;
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"))
}
}
- 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))
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;
}
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;
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)
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;
e = startswith(p, table[i].suffix);
if (e) {
- *multiplier = table[i].usec;
+ *ret = table[i].usec;
return e;
}
}
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);
if (*s != 0)
return -EINVAL;
- if (usec)
- *usec = USEC_INFINITY;
+ if (ret)
+ *ret = USEC_INFINITY;
return 0;
}
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;
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" */
}
}
- 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) {
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;
e = startswith(p, table[i].suffix);
if (e) {
- *multiplier = table[i].nsec;
+ *ret = table[i].nsec;
return e;
}
}
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;
if (*s != 0)
return -EINVAL;
- *nsec = NSEC_INFINITY;
+ *ret = NSEC_INFINITY;
return 0;
}
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;
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" */
}
}
- *nsec = r;
+ *ret = nsec;
return 0;
}
#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;
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);