Mercurial > emacs
comparison src/mktime.c @ 20903:ba17c544eb9e
automatically generated from GPLed version
author | Ulrich Drepper <drepper@redhat.com> |
---|---|
date | Mon, 16 Feb 1998 02:42:49 +0000 |
parents | b53b022d2239 |
children | 4c72cf4eeedb |
comparison
equal
deleted
inserted
replaced
20902:117024af99ea | 20903:ba17c544eb9e |
---|---|
1 /* Copyright (C) 1993, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. | 1 /* Copyright (C) 1993, 94, 95, 96, 97, 98 Free Software Foundation, Inc. |
2 Contributed by Paul Eggert (eggert@twinsun.com). | 2 Contributed by Paul Eggert (eggert@twinsun.com). |
3 | 3 |
4 NOTE: The canonical source of this file is maintained with the GNU C Library. | 4 NOTE: The canonical source of this file is maintained with the GNU C Library. |
5 Bugs can be reported to bug-glibc@prep.ai.mit.edu. | 5 Bugs can be reported to bug-glibc@prep.ai.mit.edu. |
6 | 6 |
25 | 25 |
26 #ifdef HAVE_CONFIG_H | 26 #ifdef HAVE_CONFIG_H |
27 # include <config.h> | 27 # include <config.h> |
28 #endif | 28 #endif |
29 | 29 |
30 /* Some hosts need this in order to declare localtime_r properly. */ | 30 /* Some systems need this in order to declare localtime_r properly. */ |
31 #ifndef _REENTRANT | 31 #ifndef _REENTRANT |
32 # define _REENTRANT 1 | 32 # define _REENTRANT 1 |
33 #endif | 33 #endif |
34 | 34 |
35 #ifdef _LIBC | 35 #ifdef _LIBC |
71 | 71 |
72 #ifndef CHAR_BIT | 72 #ifndef CHAR_BIT |
73 # define CHAR_BIT 8 | 73 # define CHAR_BIT 8 |
74 #endif | 74 #endif |
75 | 75 |
76 /* The extra casts work around common compiler bugs. */ | |
77 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1)) | |
78 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0. | |
79 It is necessary at least when t == time_t. */ | |
80 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \ | |
81 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0)) | |
82 #define TYPE_MAXIMUM(t) (~ (t) 0 - TYPE_MINIMUM (t)) | |
83 | |
76 #ifndef INT_MIN | 84 #ifndef INT_MIN |
77 # define INT_MIN (~0 << (sizeof (int) * CHAR_BIT - 1)) | 85 # define INT_MIN TYPE_MINIMUM (int) |
78 #endif | 86 #endif |
79 #ifndef INT_MAX | 87 #ifndef INT_MAX |
80 # define INT_MAX (~0 - INT_MIN) | 88 # define INT_MAX TYPE_MAXIMUM (int) |
81 #endif | 89 #endif |
82 | 90 |
83 #ifndef TIME_T_MIN | 91 #ifndef TIME_T_MIN |
84 /* The outer cast to time_t works around a bug in Cray C 5.0.3.0. */ | 92 # define TIME_T_MIN TYPE_MINIMUM (time_t) |
85 # define TIME_T_MIN ((time_t) \ | |
86 (0 < (time_t) -1 ? (time_t) 0 \ | |
87 : ~ (time_t) 0 << (sizeof (time_t) * CHAR_BIT - 1))) | |
88 #endif | 93 #endif |
89 #ifndef TIME_T_MAX | 94 #ifndef TIME_T_MAX |
90 # define TIME_T_MAX (~ (time_t) 0 - TIME_T_MIN) | 95 # define TIME_T_MAX TYPE_MAXIMUM (time_t) |
91 #endif | 96 #endif |
92 | 97 |
93 #define TM_YEAR_BASE 1900 | 98 #define TM_YEAR_BASE 1900 |
94 #define EPOCH_YEAR 1970 | 99 #define EPOCH_YEAR 1970 |
95 | 100 |
363 | 368 |
364 double dyear = (double) year_requested + mon_years - tm.tm_year; | 369 double dyear = (double) year_requested + mon_years - tm.tm_year; |
365 double dday = 366 * dyear + mday; | 370 double dday = 366 * dyear + mday; |
366 double dsec = 60 * (60 * (24 * dday + hour) + min) + sec_requested; | 371 double dsec = 60 * (60 * (24 * dday + hour) + min) + sec_requested; |
367 | 372 |
368 if (TIME_T_MAX / 3 - TIME_T_MIN / 3 < (dsec < 0 ? - dsec : dsec)) | 373 /* On Irix4.0.5 cc, dividing TIME_T_MIN by 3 does not produce |
374 correct results, ie., it erroneously gives a positive value | |
375 of 715827882. Setting a variable first then doing math on it | |
376 seems to work. (ghazi@caip.rutgers.edu) */ | |
377 | |
378 const time_t time_t_max = TIME_T_MAX; | |
379 const time_t time_t_min = TIME_T_MIN; | |
380 | |
381 if (time_t_max / 3 - time_t_min / 3 < (dsec < 0 ? - dsec : dsec)) | |
369 return -1; | 382 return -1; |
370 } | 383 } |
371 | 384 |
372 *tp = tm; | 385 *tp = tm; |
373 return t; | 386 return t; |