]> gcc.gnu.org Git - gcc.git/blame - libchill/abstime.c
tree.c (size_in_bytes): Return size_zero_node, not integer_zero_node.
[gcc.git] / libchill / abstime.c
CommitLineData
b79f73df
JL
1/* Implement timing-related runtime actions for CHILL.
2 Copyright (C) 1992,1993 Free Software Foundation, Inc.
3 Author: Wilfried Moser
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
201853b4
JL
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
b79f73df 21
502b941f
JL
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. */
28
b79f73df
JL
29#include <time.h>
30#include "rtltypes.h"
31
32EXCEPTION (rangefail);
33
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
40
41extern void __cause_ex1 (char *ex, char *file, int lineno);
42
43#define CAUSE_RANGEFAIL __cause_ex1 ("rangefail", filename, lineno)
44
45/*
46 * function _abstime
47 *
48 * parameters:
49 * mask - mask of valid values
50 * year
51 * month
52 * day
53 * hour
54 * minute
55 * second
56 *
57 * returns:
58 * unsigned long
59 *
60 * exceptions:
61 * rangefail
62 *
63 * abstract:
64 * perform the ABSTIME builtin call
65 *
66 */
67
68unsigned 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;
74{
75 struct tm *time_str;
76 time_t result, current_time;
77
78 /* first of all get current time */
79 if ((current_time = time (0)) == (time_t)-1)
80 /* FIXME: what excpetion ?? */
81 CAUSE_RANGEFAIL;
82
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;
87
88 /* convert current time to struct tm */
89 time_str = localtime (&current_time);
90
91 if (mask & YEAR_VALID)
92 {
93 if (year < 1900)
94 CAUSE_RANGEFAIL;
95 time_str->tm_year = year - 1900;
96 }
97
98 if (mask & MONTH_VALID)
99 {
100 if (month < 1 || month > 12)
101 CAUSE_RANGEFAIL;
102 time_str->tm_mon = month - 1;
103 }
104
105 if (mask & DAY_VALID)
106 {
107 if (day < 1 || day > 31)
108 CAUSE_RANGEFAIL;
109 time_str->tm_mday = day;
110 }
111
112 if (mask & HOUR_VALID)
113 {
114 if (hour < 0 || hour > 23)
115 CAUSE_RANGEFAIL;
116 time_str->tm_hour = hour;
117 }
118
119 if (mask & MINUTE_VALID)
120 {
121 if (minute < 0 || minute > 59)
122 CAUSE_RANGEFAIL;
123 time_str->tm_min = minute;
124 }
125
126 if (mask & SECOND_VALID)
127 {
128 if (second < 0 || second > 59)
129 CAUSE_RANGEFAIL;
130 time_str->tm_sec = second;
131 }
132
133 /* do it */
134 time_str->tm_isdst = -1;
135 if ((result = mktime (time_str)) == (time_t)-1)
136 CAUSE_RANGEFAIL;
137
138 return (unsigned long)result;
139}
This page took 0.122466 seconds and 5 git commands to generate.