2
* Copyright 1991 - 1994, Julianne Frances Haugh
2
* Copyright (c) 1991 - 1994, Julianne Frances Haugh
3
* Copyright (c) 1996 - 1999, Marek Michałkiewicz
4
* Copyright (c) 2003 - 2005, Tomasz Kłoczko
5
* Copyright (c) 2008 , Nicolas François
3
6
* All rights reserved.
5
8
* Redistribution and use in source and binary forms, with or without
10
13
* 2. Redistributions in binary form must reproduce the above copyright
11
14
* notice, this list of conditions and the following disclaimer in the
12
15
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of Julianne F. Haugh nor the names of its contributors
14
* may be used to endorse or promote products derived from this software
15
* without specific prior written permission.
16
* 3. The name of the copyright holders or contributors may not be used to
17
* endorse or promote products derived from this software without
18
* specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY JULIE HAUGH AND CONTRIBUTORS ``AS IS'' AND
18
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
* ARE DISCLAIMED. IN NO EVENT SHALL JULIE HAUGH OR CONTRIBUTORS BE LIABLE
21
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
33
#if !defined(__GLIBC__)
66
69
* which is not what we expect, unless you're a BOFH :-).
67
70
* (useradd sets sp_expire = current date for new lusers)
69
if (!str || *str == '\0')
72
if ((NULL == str) || ('\0' == *str)) {
72
76
t = get_date (str, (time_t *) 0);
73
if (t == (time_t) - 1)
77
if ((time_t) - 1 == t) {
75
80
/* convert seconds to days since 1970-01-01 */
76
return (t + DAY / 2) / DAY;
81
return (long) (t + DAY / 2) / DAY;
79
84
#else /* !USE_GETDATE */
126
131
memzero (&tp, sizeof tp);
127
132
for (fmt = date_formats; *fmt; fmt++) {
128
133
cp = strptime ((char *) str, *fmt, &tp);
129
if (!cp || *cp != '\0')
134
if ((NULL == cp) || ('\0' != *cp)) {
132
138
result = mktime (&tp);
133
if (result == (time_t) - 1)
139
if ((time_t) - 1 == result) {
136
return result / DAY; /* success */
143
return (long) (result / DAY); /* success */
148
155
* is compiled in ...
151
if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3)
158
if (sscanf (str, "%d/%d/%d%c", &year, &month, &day, slop) != 3) {
155
163
* the month, day of the month, and year are checked for
160
if (month < 1 || month > 12)
166
if ((month != 2 || (year % 4) != 0) && day > days[month])
168
else if ((month == 2 && (year % 4) == 0) && day > 29)
168
if ((month < 1) || (month > 12)) {
176
if ( ((2 != month) || ((year % 4) != 0))
177
&& (day > days[month])) {
179
} else if ((month == 2) && ((year % 4) == 0) && (day > 29)) {
185
} else if (year <= 69) {
187
} else if (year <= 99) {
179
192
* On systems with 32-bit signed time_t, time wraps around in 2038