CBMC
time.c
Go to the documentation of this file.
1 /* FUNCTION: time */
2 
3 #ifndef __CPROVER_TIME_H_INCLUDED
4 #include <time.h>
5 #define __CPROVER_TIME_H_INCLUDED
6 #endif
7 
8 #undef time
9 
11 
12 time_t time(time_t *tloc)
13 {
14  time_t res=__VERIFIER_nondet_time_t();
15  if(tloc)
16  *tloc = res;
17  return res;
18 }
19 
20 /* FUNCTION: _time64 */
21 
22 #ifdef _WIN32
23 
24 # ifndef __CPROVER_TIME_H_INCLUDED
25 # include <time.h>
26 # define __CPROVER_TIME_H_INCLUDED
27 # endif
28 
29 time_t __VERIFIER_nondet_time_t(void);
30 
31 time_t _time64(time_t *tloc)
32 {
33  time_t res = __VERIFIER_nondet_time_t();
34  if(tloc)
35  *tloc = res;
36  return res;
37 }
38 
39 #endif
40 
41 /* FUNCTION: _time32 */
42 
43 #if defined(_WIN32) && defined(_USE_32BIT_TIME_T)
44 
45 # ifndef __CPROVER_TIME_H_INCLUDED
46 # include <time.h>
47 # define __CPROVER_TIME_H_INCLUDED
48 # endif
49 
50 __time32_t __VERIFIER_nondet_time32_t(void);
51 
52 __time32_t _time32(__time32_t *tloc)
53 {
54  __time32_t res = __VERIFIER_nondet_time32_t();
55  if(tloc)
56  *tloc = res;
57  return res;
58 }
59 
60 #endif
61 
62 /* FUNCTION: gmtime */
63 
64 #ifndef __CPROVER_TIME_H_INCLUDED
65 #include <time.h>
66 #define __CPROVER_TIME_H_INCLUDED
67 #endif
68 
69 #undef gmtime
70 
71 struct tm *gmtime(const time_t *clock)
72 {
73  // not very general, may be too restrictive
74  // need to set the fields to something meaningful
75  (void)*clock;
76  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
77  __CPROVER_event("invalidate_pointer", "gmtime_result");
78  struct tm *gmtime_result;
79  __CPROVER_set_must(gmtime_result, "gmtime_result");
80  return gmtime_result;
81  #else
82  static struct tm return_value;
83  return &return_value;
84  #endif
85 }
86 
87 /* FUNCTION: gmtime_r */
88 
89 #ifndef __CPROVER_TIME_H_INCLUDED
90 #include <time.h>
91 #define __CPROVER_TIME_H_INCLUDED
92 #endif
93 
94 #undef gmtime
95 
96 struct tm *gmtime_r(const time_t *clock, struct tm *result)
97 {
98  // need to set the fields to something meaningful
99  (void)*clock;
100  return result;
101 }
102 
103 /* FUNCTION: localtime */
104 
105 #ifndef __CPROVER_TIME_H_INCLUDED
106 #include <time.h>
107 #define __CPROVER_TIME_H_INCLUDED
108 #endif
109 
110 #undef localtime
111 
112 struct tm *localtime(const time_t *clock)
113 {
114  // not very general, may be too restrictive
115  // need to set the fields to something meaningful
116  (void)*clock;
117  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
118  __CPROVER_event("invalidate_pointer", "localtime_result");
119  struct tm *localtime_result;
120  __CPROVER_set_must(localtime_result, "localtime_result");
121  return localtime_result;
122  #else
123  static struct tm return_value;
124  return &return_value;
125  #endif
126 }
127 
128 /* FUNCTION: localtime_r */
129 
130 #ifndef __CPROVER_TIME_H_INCLUDED
131 #include <time.h>
132 #define __CPROVER_TIME_H_INCLUDED
133 #endif
134 
135 #undef localtime
136 
137 struct tm *localtime_r(const time_t *clock, struct tm *result)
138 {
139  // need to set the fields to something meaningful
140  (void)*clock;
141  return result;
142 }
143 
144 /* FUNCTION: mktime */
145 
146 #ifndef __CPROVER_TIME_H_INCLUDED
147 #include <time.h>
148 #define __CPROVER_TIME_H_INCLUDED
149 #endif
150 
151 #undef mktime
152 
153 time_t __VERIFIER_nondet_time_t(void);
154 
155 time_t mktime(struct tm *timeptr)
156 {
157  (void)*timeptr;
158  time_t result=__VERIFIER_nondet_time_t();
159  return result;
160 }
161 
162 /* FUNCTION: timegm */
163 
164 #ifndef __CPROVER_TIME_H_INCLUDED
165 #include <time.h>
166 #define __CPROVER_TIME_H_INCLUDED
167 #endif
168 
169 #undef timegm
170 
171 time_t __VERIFIER_nondet_time_t(void);
172 
173 time_t timegm(struct tm *timeptr)
174 {
175  (void)*timeptr;
176  time_t result=__VERIFIER_nondet_time_t();
177  return result;
178 }
179 
180 /* FUNCTION: asctime */
181 
182 #ifndef __CPROVER_TIME_H_INCLUDED
183 #include <time.h>
184 #define __CPROVER_TIME_H_INCLUDED
185 #endif
186 
187 char *asctime(const struct tm *timeptr)
188 {
189  (void)*timeptr;
190  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
191  __CPROVER_event("invalidate_pointer", "asctime_result");
192  char *asctime_result;
193  __CPROVER_set_must(asctime_result, "asctime_result");
194  return asctime_result;
195  #else
196  static char asctime_result[1];
197  return asctime_result;
198  #endif
199 }
200 
201 /* FUNCTION: ctime */
202 
203 #ifndef __CPROVER_TIME_H_INCLUDED
204 #include <time.h>
205 #define __CPROVER_TIME_H_INCLUDED
206 #endif
207 
208 char *ctime(const time_t *clock)
209 {
210  (void)*clock;
211  #ifdef __CPROVER_CUSTOM_BITVECTOR_ANALYSIS
212  __CPROVER_event("invalidate_pointer", "ctime_result");
213  char *ctime_result;
214  __CPROVER_set_must(ctime_result, "ctime_result");
215  return ctime_result;
216  #else
217  static char ctime_result[1];
218  return ctime_result;
219  #endif
220 }
221 
222 /* FUNCTION: strftime */
223 
224 #ifndef __CPROVER_TIME_H_INCLUDED
225 # include <time.h>
226 # define __CPROVER_TIME_H_INCLUDED
227 #endif
228 
229 __CPROVER_size_t __VERIFIER_nondet_size_t(void);
230 
231 __CPROVER_size_t
232 strftime(char *s, __CPROVER_size_t max, const char *format, const struct tm *tm)
233 {
234  (void)*format;
235  (void)*tm;
236  __CPROVER_havoc_slice(s, max);
237  __CPROVER_size_t length = __VERIFIER_nondet_size_t();
238  if(length >= max)
239  return 0;
240  s[length] = '\0';
241  return length;
242 }
243 
244 /* FUNCTION: _strftime */
245 
246 #ifndef __CPROVER_TIME_H_INCLUDED
247 # include <time.h>
248 # define __CPROVER_TIME_H_INCLUDED
249 #endif
250 
251 __CPROVER_size_t __VERIFIER_nondet_size_t(void);
252 
253 __CPROVER_size_t _strftime(
254  char *s,
255  __CPROVER_size_t max,
256  const char *format,
257  const struct tm *tm)
258 {
259  (void)*format;
260  (void)*tm;
261  __CPROVER_havoc_slice(s, max);
262  __CPROVER_size_t length = __VERIFIER_nondet_size_t();
263  if(length >= max)
264  return 0;
265  s[length] = '\0';
266  return length;
267 }
void __CPROVER_havoc_slice(void *, __CPROVER_size_t)
void __CPROVER_set_must(const void *, const char *)
static format_containert< T > format(const T &o)
Definition: format.h:37
struct tm * gmtime_r(const time_t *clock, struct tm *result)
Definition: time.c:96
time_t __VERIFIER_nondet_time_t(void)
struct tm * localtime(const time_t *clock)
Definition: time.c:112
time_t timegm(struct tm *timeptr)
Definition: time.c:173
char * asctime(const struct tm *timeptr)
Definition: time.c:187
__CPROVER_size_t strftime(char *s, __CPROVER_size_t max, const char *format, const struct tm *tm)
Definition: time.c:232
char * ctime(const time_t *clock)
Definition: time.c:208
time_t time(time_t *tloc)
Definition: time.c:12
__CPROVER_size_t __VERIFIER_nondet_size_t(void)
struct tm * gmtime(const time_t *clock)
Definition: time.c:71
__CPROVER_size_t _strftime(char *s, __CPROVER_size_t max, const char *format, const struct tm *tm)
Definition: time.c:253
struct tm * localtime_r(const time_t *clock, struct tm *result)
Definition: time.c:137
time_t mktime(struct tm *timeptr)
Definition: time.c:155