scron

simple cron daemon
git clone git://git.2f30.org/scron
Log | Files | Refs | README | LICENSE

commit 8c8be8b36a399c461d5e90f166aaed2ce23c8452
parent a4cbbfd8806e093580b8fcb9105573f5adf69ee3
Author: sin <sin@2f30.org>
Date:   Thu,  3 Jul 2014 14:34:39 +0100

Use a switch statement for parsing ranges

Diffstat:
Mcrond.c | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/crond.c b/crond.c @@ -180,20 +180,29 @@ parsefield(const char *field, int low, int high, struct range *r) r->high = -1; return 0; } + max = -1; min = strtol(field, &e1, 10); - if (e1[0] == '-') { + + switch (e1[0]) { + case '-': e1++; max = strtol(e1, &e2, 10); if (e2[0] != '\0') return -1; - } else if (e1[0] != '\0') + break; + case '\0': + break; + default: return -1; + } + if (min < low || min > high) return -1; if (max != -1) if (max < low || max > high) return -1; + r->low = min; r->high = max; return 0;