* Makefile.in: Rebuilt.
[official-gcc.git] / libchill / abstime.c
blobbf3d6149110630f706e0ed024e9f6c40d10a8b29
1 /* Implement timing-related runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
3 Author: Wilfried Moser
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)
10 any later version.
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, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* As a special exception, if you link this library with other files,
23 some of which are compiled with GCC, to produce an executable,
24 this library does not by itself cause the resulting executable
25 to be covered by the GNU General Public License.
26 This exception does not however invalidate any other reasons why
27 the executable file might be covered by the GNU General Public License. */
29 #include <time.h>
30 #include "rtltypes.h"
32 EXCEPTION (rangefail);
34 #define SECOND_VALID 1
35 #define MINUTE_VALID 2
36 #define HOUR_VALID 4
37 #define DAY_VALID 8
38 #define MONTH_VALID 16
39 #define YEAR_VALID 32
41 extern void __cause_ex1 (char *ex, char *file, int lineno);
43 #define CAUSE_RANGEFAIL __cause_ex1 ("rangefail", filename, lineno)
46 * function _abstime
48 * parameters:
49 * mask - mask of valid values
50 * year
51 * month
52 * day
53 * hour
54 * minute
55 * second
57 * returns:
58 * unsigned long
60 * exceptions:
61 * rangefail
63 * abstract:
64 * perform the ABSTIME builtin call
68 unsigned long
69 _abstime (mask, year, month, day, hour, minute, second,
70 filename, lineno)
71 int mask, year, month, day, hour, minute, second;
72 char *filename;
73 int lineno;
75 struct tm *time_str;
76 time_t result, current_time;
78 /* first of all get current time */
79 if ((current_time = time (0)) == (time_t)-1)
80 /* FIXME: what excpetion ?? */
81 CAUSE_RANGEFAIL;
83 /* if we just have to determine the current time, we are ready.
84 This is shown by mask == 0. */
85 if (mask == 0)
86 return (unsigned long)current_time;
88 /* convert current time to struct tm */
89 time_str = localtime (&current_time);
91 if (mask & YEAR_VALID)
93 if (year < 1900)
94 CAUSE_RANGEFAIL;
95 time_str->tm_year = year - 1900;
98 if (mask & MONTH_VALID)
100 if (month < 1 || month > 12)
101 CAUSE_RANGEFAIL;
102 time_str->tm_mon = month - 1;
105 if (mask & DAY_VALID)
107 if (day < 1 || day > 31)
108 CAUSE_RANGEFAIL;
109 time_str->tm_mday = day;
112 if (mask & HOUR_VALID)
114 if (hour < 0 || hour > 23)
115 CAUSE_RANGEFAIL;
116 time_str->tm_hour = hour;
119 if (mask & MINUTE_VALID)
121 if (minute < 0 || minute > 59)
122 CAUSE_RANGEFAIL;
123 time_str->tm_min = minute;
126 if (mask & SECOND_VALID)
128 if (second < 0 || second > 59)
129 CAUSE_RANGEFAIL;
130 time_str->tm_sec = second;
133 /* do it */
134 time_str->tm_isdst = -1;
135 if ((result = mktime (time_str)) == (time_t)-1)
136 CAUSE_RANGEFAIL;
138 return (unsigned long)result;