1 /* Implement timing-related runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* As a special exception, if you link this library with other files,
22 some of which are compiled with GCC, to produce an executable,
23 this library does not by itself cause the resulting executable
24 to be covered by the GNU General Public License.
25 This exception does not however invalidate any other reasons why
26 the executable file might be covered by the GNU General Public License. */
31 EXCEPTION (rangefail);
33 #define SECOND_VALID 1
34 #define MINUTE_VALID 2
37 #define MONTH_VALID 16
40 extern void __cause_ex1 (char *ex, char *file, int lineno);
42 #define CAUSE_RANGEFAIL __cause_ex1 ("rangefail", filename, lineno)
48 * mask - mask of valid values
63 * perform the ABSTIME builtin call
68 _abstime (mask, year, month, day, hour, minute, second,
70 int mask, year, month, day, hour, minute, second;
75 time_t result, current_time;
77 /* first of all get current time */
78 if ((current_time = time (0)) == (time_t)-1)
79 /* FIXME: what excpetion ?? */
82 /* if we just have to determine the current time, we are ready.
83 This is shown by mask == 0. */
85 return (unsigned long)current_time;
87 /* convert current time to struct tm */
88 time_str = localtime (¤t_time);
90 if (mask & YEAR_VALID)
94 time_str->tm_year = year - 1900;
97 if (mask & MONTH_VALID)
99 if (month < 1 || month > 12)
101 time_str->tm_mon = month - 1;
104 if (mask & DAY_VALID)
106 if (day < 1 || day > 31)
108 time_str->tm_mday = day;
111 if (mask & HOUR_VALID)
113 if (hour < 0 || hour > 23)
115 time_str->tm_hour = hour;
118 if (mask & MINUTE_VALID)
120 if (minute < 0 || minute > 59)
122 time_str->tm_min = minute;
125 if (mask & SECOND_VALID)
127 if (second < 0 || second > 59)
129 time_str->tm_sec = second;
133 time_str->tm_isdst = -1;
134 if ((result = mktime (time_str)) == (time_t)-1)
137 return (unsigned long)result;