Always signal an error if time returns -1. Not uses errno-error as
only few systems set errno if mktime fails.
This commit is contained in:
parent
11972910cd
commit
13dabb8f4e
|
@ -113,15 +113,19 @@
|
|||
(if (pair? args)
|
||||
(if (null? (cdr args))
|
||||
(let ((date (check-arg date? (car args) time)))
|
||||
(%date->time (date:seconds date)
|
||||
(date:minute date)
|
||||
(date:hour date)
|
||||
(date:month-day date)
|
||||
(date:month date)
|
||||
(date:year date)
|
||||
(date:tz-name date) ; #f or string
|
||||
(date:tz-secs date) ; #f or int
|
||||
(date:summer? date)))
|
||||
(let ((err?.time
|
||||
(%date->time (date:seconds date)
|
||||
(date:minute date)
|
||||
(date:hour date)
|
||||
(date:month-day date)
|
||||
(date:month date)
|
||||
(date:year date)
|
||||
(date:tz-name date) ; #f or string
|
||||
(date:tz-secs date) ; #f or int
|
||||
(date:summer? date))))
|
||||
(if (car err?.time)
|
||||
(error "Error converting date to time." args)
|
||||
(cdr err?.time))))
|
||||
(error "Too many arguments to TIME procedure" args))
|
||||
(%time))) ; Fast path for (time).
|
||||
|
||||
|
|
16
scsh/time1.c
16
scsh/time1.c
|
@ -224,7 +224,7 @@ s48_value date2time(s48_value sec, s48_value min, s48_value hour,
|
|||
{
|
||||
time_t t;
|
||||
struct tm d;
|
||||
|
||||
int err = 0;
|
||||
d.tm_sec = s48_extract_fixnum (sec);
|
||||
d.tm_min = s48_extract_fixnum (min);
|
||||
d.tm_hour = s48_extract_fixnum (hour);
|
||||
|
@ -238,12 +238,8 @@ s48_value date2time(s48_value sec, s48_value min, s48_value hour,
|
|||
environ = utc_env; /* time temporarily. */
|
||||
tzset(); /* NetBSD, SunOS POSIX-noncompliance requires this. */
|
||||
d.tm_isdst = 0; /* FreeBSD, at least, needs this or it sulks. */
|
||||
errno = 0;
|
||||
t = mktime(&d);
|
||||
/* t == -1 => you probably have an error. */
|
||||
if ((t == -1) && (errno != 0))
|
||||
/* Sorry, we only have a version with 5 arguments..*/
|
||||
s48_raise_os_error_5 (errno, sec, min, hour, mday, month);
|
||||
if (t == -1) err = 1;
|
||||
t -= s48_extract_fixnum(tz_secs);
|
||||
environ = oldenv;
|
||||
}
|
||||
|
@ -260,8 +256,7 @@ s48_value date2time(s48_value sec, s48_value min, s48_value hour,
|
|||
|
||||
d.tm_isdst = -1;
|
||||
t = mktime(&d);
|
||||
if ((t == -1) && (errno != 0))
|
||||
s48_raise_os_error_5 (errno, sec, min, hour, mday, month);
|
||||
if (t == -1) err = 1;
|
||||
revert_env(oldenv);
|
||||
}
|
||||
|
||||
|
@ -270,11 +265,10 @@ s48_value date2time(s48_value sec, s48_value min, s48_value hour,
|
|||
errno = 0;
|
||||
d.tm_isdst = -1;
|
||||
t = mktime(&d);
|
||||
if ((t == -1) && (errno != 0))
|
||||
s48_raise_os_error_5 (errno, sec, min, hour, mday, month);
|
||||
if (t == -1) err = 1;
|
||||
}
|
||||
|
||||
return s48_enter_integer(t);
|
||||
return s48_cons (err ? S48_TRUE : S48_FALSE, s48_enter_integer(t));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue