From 5c6766a3ae30770784d054ffbf47faf290dee80e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 1 Aug 2015 12:22:18 -0500 Subject: Replace xcheckrange() with atolx_range() --- toys/posix/cal.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'toys/posix/cal.c') diff --git a/toys/posix/cal.c b/toys/posix/cal.c index bb476dfd..bd3afad4 100644 --- a/toys/posix/cal.c +++ b/toys/posix/cal.c @@ -64,14 +64,6 @@ static char *calstrings(char *buf, struct tm *tm) return buf; } -void xcheckrange(long val, long low, long high) -{ - char *err = "%ld %s than %ld"; - - if (val < low) error_exit(err, val, "less", low); - if (val > high) error_exit(err, val, "greater", high); -} - // Worst case scenario toybuf usage: sizeof(struct tm) plus 21 bytes/line // plus 8 lines/month plus 12 months, comes to a bit over 2k of our 4k buffer. @@ -86,12 +78,12 @@ void cal_main(void) buf += sizeof(struct tm); // Last argument is year, one before that (if any) is month. - xcheckrange(tm->tm_year = atol(toys.optargs[--toys.optc]),1,9999); + tm->tm_year = atolx_range(toys.optargs[--toys.optc], 1, 9999); tm->tm_year -= 1900; tm->tm_mday = 1; tm->tm_hour = 12; // noon to avoid timezone weirdness if (toys.optc) { - xcheckrange(tm->tm_mon = atol(toys.optargs[--toys.optc]),1,12); + tm->tm_mon = atolx_range(toys.optargs[--toys.optc], 1, 12); tm->tm_mon--; // Print 12 months of the year -- cgit v1.2.3