aboutsummaryrefslogtreecommitdiffstats
path: root/src/parse_time.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@member.fsf.org>2015-12-28 01:43:39 +0100
committerMattias Andrée <maandree@member.fsf.org>2015-12-28 01:43:39 +0100
commit0de4466f7cefb55584b24589acaca2284fea8d24 (patch)
tree3097f66bc66a0e132902243bc6ef97f699a56710 /src/parse_time.c
parentthe socket shall be opened on fd 3 (you will see why later) (diff)
downloadsat-0de4466f7cefb55584b24589acaca2284fea8d24.tar.gz
sat-0de4466f7cefb55584b24589acaca2284fea8d24.tar.bz2
sat-0de4466f7cefb55584b24589acaca2284fea8d24.tar.xz
fix errors and tidy up
Signed-off-by: Mattias Andrée <maandree@member.fsf.org>
Diffstat (limited to 'src/parse_time.c')
-rw-r--r--src/parse_time.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/parse_time.c b/src/parse_time.c
index d86ef43..51e9011 100644
--- a/src/parse_time.c
+++ b/src/parse_time.c
@@ -58,6 +58,11 @@
*/
extern char *argv0;
+/**
+ * The highest value that can be stored in `time_t`.
+ */
+const time_t timemax = (sizeof(time_t) == sizeof(long long int)) ? LLONG_MAX : LONG_MAX;
+
/**
@@ -81,6 +86,7 @@ strtotime(const char *str, const char **end)
time_t rc;
long long int rcll;
long int rcl;
+ char **end_ = (char **)end;
if (!isdigit(*str))
FAIL(EINVAL);
@@ -91,10 +97,10 @@ strtotime(const char *str, const char **end)
errno = 0;
if (sizeof(time_t) == sizeof(long long int)) {
- rcll = strtoll(str, end, 10);
+ rcll = strtoll(str, end_, 10);
rc = (time_t)rcll;
} else {
- rcl = strtol(str, end, 10);
+ rcl = strtol(str, end_, 10);
rc = (time_t)rcl;
}
@@ -117,9 +123,7 @@ strtotime(const char *str, const char **end)
static int
parse_time_time(const char *str, struct timespec *ts, const char **end)
{
- char *end;
time_t t;
- const time_t timemax = (sizeof(time_t) == sizeof(long long int)) ? LLONG_MAX : LONG_MAX;
memset(ts, 0, sizeof(*ts));
@@ -208,9 +212,9 @@ int
parse_time(const char *str, struct timespec *ts, clockid_t *clk)
{
struct timespec now;
- int plus = *str == '+';
- char *start = str;
- char *end;
+ int points, plus = *str == '+';
+ const char *start = str;
+ const char *end;
time_t adj;
/* Get current time and clock. */
@@ -218,7 +222,7 @@ parse_time(const char *str, struct timespec *ts, clockid_t *clk)
*clk = plus ? CLOCK_MONOTONIC : CLOCK_REALTIME;
/* Mañana? */
- if (!strcmp("mañana")) { /* Do not documented. */
+ if (!strcmp(str, "mañana")) { /* Do not documented. */
ts->tv_sec = now.tv_sec + ONE_DAY;
ts->tv_nsec = now.tv_nsec;
return 0;
@@ -228,7 +232,7 @@ parse_time(const char *str, struct timespec *ts, clockid_t *clk)
if (strchr(str, ':')) {
if (parse_time_time(str, ts, &end))
return -1;
- adj = now.sec - (now.sec % ONE_DAY);
+ adj = now.tv_sec - (now.tv_sec % ONE_DAY);
ADD(ts->tv_sec, adj); /* In case the HH is really large. */
} else {
if (parse_time_seconds(str + plus, ts, &end))
@@ -244,7 +248,7 @@ parse_time(const char *str, struct timespec *ts, clockid_t *clk)
}
/* Parse up to nanosecond resolution. */
- for (; isdigit(*str); points++) {
+ for (points = 0; isdigit(*str); points++) {
if (points < 9) {
ts->tv_nsec *= 10;
ts->tv_nsec += *str++ & 15;
@@ -260,10 +264,10 @@ parse_time(const char *str, struct timespec *ts, clockid_t *clk)
/* Check for error at end, and missing explicit UTC. */
if (*str) {
if (*clk == CLOCK_MONOTONIC)
- FAIL(einval);
+ FAIL(EINVAL);
while (*str == ' ') str++;
if (!strcasecmp(str, "Z") && !strcasecmp(str, "UTC"))
- FAIL(einval);
+ FAIL(EINVAL);
} else if (*clk == CLOCK_REALTIME) {
fprintf(stderr,
"%s: warning: parsing as UTC, you can avoid "