2014-06-16 14:55:09 +00:00
|
|
|
/*-
|
2014-06-18 23:34:48 +00:00
|
|
|
* Copyright (c) 2014 Gary Mills
|
|
|
|
* Copyright 2011, Nexenta Systems, Inc. All rights reserved.
|
1997-08-09 15:38:14 +00:00
|
|
|
* Copyright (c) 1994 Powerdog Industries. All rights reserved.
|
|
|
|
*
|
2011-11-20 14:45:42 +00:00
|
|
|
* Copyright (c) 2011 The FreeBSD Foundation
|
|
|
|
* All rights reserved.
|
|
|
|
* Portions of this software were developed by David Chisnall
|
|
|
|
* under sponsorship from the FreeBSD Foundation.
|
|
|
|
*
|
1997-08-09 15:43:59 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
1997-08-09 15:38:14 +00:00
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
|
|
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2014-06-16 14:55:09 +00:00
|
|
|
*
|
|
|
|
* The views and conclusions contained in the software and documentation
|
|
|
|
* are those of the authors and should not be interpreted as representing
|
|
|
|
* official policies, either expressed or implied, of Powerdog Industries.
|
1997-08-09 15:38:14 +00:00
|
|
|
*/
|
|
|
|
|
2003-02-16 17:29:11 +00:00
|
|
|
#include <sys/cdefs.h>
|
1997-08-09 15:38:14 +00:00
|
|
|
#ifndef lint
|
1997-08-09 15:43:59 +00:00
|
|
|
#ifndef NOID
|
2003-02-16 17:29:11 +00:00
|
|
|
static char copyright[] __unused =
|
1997-08-09 15:38:14 +00:00
|
|
|
"@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved.";
|
2003-02-16 17:29:11 +00:00
|
|
|
static char sccsid[] __unused = "@(#)strptime.c 0.1 (Powerdog) 94/03/27";
|
1997-08-09 15:43:59 +00:00
|
|
|
#endif /* !defined NOID */
|
1997-08-09 15:38:14 +00:00
|
|
|
#endif /* not lint */
|
2002-03-22 21:53:29 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
1997-08-09 15:38:14 +00:00
|
|
|
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "namespace.h"
|
1997-08-09 15:38:14 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <ctype.h>
|
2003-11-17 04:19:15 +00:00
|
|
|
#include <errno.h>
|
2001-07-13 13:59:24 +00:00
|
|
|
#include <stdlib.h>
|
1997-08-09 15:38:14 +00:00
|
|
|
#include <string.h>
|
1999-07-06 05:05:39 +00:00
|
|
|
#include <pthread.h>
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "un-namespace.h"
|
|
|
|
#include "libc_private.h"
|
1997-08-09 15:43:59 +00:00
|
|
|
#include "timelocal.h"
|
1997-08-09 15:38:14 +00:00
|
|
|
|
2011-11-20 14:45:42 +00:00
|
|
|
static char * _strptime(const char *, const char *, struct tm *, int *, locale_t);
|
1999-07-04 08:54:26 +00:00
|
|
|
|
2014-06-18 02:36:21 +00:00
|
|
|
#define asizeof(a) (sizeof (a) / sizeof ((a)[0]))
|
1999-07-06 05:05:39 +00:00
|
|
|
|
|
|
|
static char *
|
2011-11-20 14:45:42 +00:00
|
|
|
_strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp,
|
|
|
|
locale_t locale)
|
1997-08-09 15:38:14 +00:00
|
|
|
{
|
1997-08-09 15:43:59 +00:00
|
|
|
char c;
|
|
|
|
const char *ptr;
|
2014-06-18 02:36:21 +00:00
|
|
|
int i, len;
|
1999-11-30 08:05:09 +00:00
|
|
|
int Ealternative, Oalternative;
|
2011-11-20 14:45:42 +00:00
|
|
|
struct lc_time_T *tptr = __get_current_time_locale(locale);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
ptr = fmt;
|
|
|
|
while (*ptr != 0) {
|
|
|
|
if (*buf == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
c = *ptr++;
|
|
|
|
|
|
|
|
if (c != '%') {
|
2011-11-20 14:45:42 +00:00
|
|
|
if (isspace_l((unsigned char)c, locale))
|
|
|
|
while (*buf != 0 &&
|
|
|
|
isspace_l((unsigned char)*buf, locale))
|
1997-08-09 15:43:59 +00:00
|
|
|
buf++;
|
|
|
|
else if (c != *buf++)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
1999-11-30 08:05:09 +00:00
|
|
|
Ealternative = 0;
|
|
|
|
Oalternative = 0;
|
|
|
|
label:
|
1997-08-09 15:43:59 +00:00
|
|
|
c = *ptr++;
|
|
|
|
switch (c) {
|
|
|
|
case 0:
|
|
|
|
case '%':
|
|
|
|
if (*buf++ != '%')
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-30 08:05:09 +00:00
|
|
|
case '+':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, tptr->date_fmt, tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-30 08:05:09 +00:00
|
|
|
case 'C':
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-11-30 08:05:09 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
/* XXX This will break for 3-digit centuries. */
|
|
|
|
len = 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++) {
|
1999-11-30 08:05:09 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1999-11-30 08:05:09 +00:00
|
|
|
}
|
|
|
|
if (i < 19)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-11-30 08:05:09 +00:00
|
|
|
|
|
|
|
tm->tm_year = i * 100 - 1900;
|
|
|
|
break;
|
|
|
|
|
1997-08-09 15:43:59 +00:00
|
|
|
case 'c':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, tptr->c_fmt, tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, "%m/%d/%y", tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
1999-11-30 08:05:09 +00:00
|
|
|
case 'E':
|
1999-11-30 19:24:07 +00:00
|
|
|
if (Ealternative || Oalternative)
|
|
|
|
break;
|
1999-11-30 08:05:09 +00:00
|
|
|
Ealternative++;
|
|
|
|
goto label;
|
|
|
|
|
|
|
|
case 'O':
|
1999-11-30 19:24:07 +00:00
|
|
|
if (Ealternative || Oalternative)
|
|
|
|
break;
|
1999-11-30 08:05:09 +00:00
|
|
|
Oalternative++;
|
|
|
|
goto label;
|
|
|
|
|
1999-11-30 19:24:07 +00:00
|
|
|
case 'F':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, "%Y-%m-%d", tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1999-11-30 19:24:07 +00:00
|
|
|
break;
|
|
|
|
|
1997-08-09 15:43:59 +00:00
|
|
|
case 'R':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, "%H:%M", tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, "%H:%M:%S", tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, tptr->X_fmt, tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
2011-11-20 14:45:42 +00:00
|
|
|
buf = _strptime(buf, tptr->x_fmt, tm, GMTp, locale);
|
2014-06-18 02:36:21 +00:00
|
|
|
if (buf == NULL)
|
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'j':
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = 3;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++){
|
1997-08-09 15:43:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
1999-11-10 14:40:59 +00:00
|
|
|
if (i < 1 || i > 366)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-11-10 14:40:59 +00:00
|
|
|
tm->tm_yday = i - 1;
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'M':
|
|
|
|
case 'S':
|
2011-11-20 14:45:42 +00:00
|
|
|
if (*buf == 0 ||
|
|
|
|
isspace_l((unsigned char)*buf, locale))
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++){
|
1997-08-09 15:43:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
|
|
|
|
1999-11-10 14:40:59 +00:00
|
|
|
if (c == 'M') {
|
|
|
|
if (i > 59)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
tm->tm_min = i;
|
1999-11-10 14:40:59 +00:00
|
|
|
} else {
|
|
|
|
if (i > 60)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
tm->tm_sec = i;
|
1999-11-10 14:40:59 +00:00
|
|
|
}
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'H':
|
|
|
|
case 'I':
|
|
|
|
case 'k':
|
|
|
|
case 'l':
|
1999-12-08 15:49:10 +00:00
|
|
|
/*
|
|
|
|
* Of these, %l is the only specifier explicitly
|
|
|
|
* documented as not being zero-padded. However,
|
|
|
|
* there is no harm in allowing zero-padding.
|
|
|
|
*
|
|
|
|
* XXX The %l specifier may gobble one too many
|
|
|
|
* digits if used incorrectly.
|
|
|
|
*/
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++) {
|
1997-08-09 15:43:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
|
|
|
if (c == 'H' || c == 'k') {
|
|
|
|
if (i > 23)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-12-08 11:11:40 +00:00
|
|
|
} else if (i > 12)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
tm->tm_hour = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'p':
|
1999-12-08 15:49:10 +00:00
|
|
|
/*
|
|
|
|
* XXX This is bogus if parsed before hour-related
|
|
|
|
* specifiers.
|
|
|
|
*/
|
2001-02-08 17:08:13 +00:00
|
|
|
len = strlen(tptr->am);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf, tptr->am, len, locale) == 0) {
|
1997-08-09 15:43:59 +00:00
|
|
|
if (tm->tm_hour > 12)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
if (tm->tm_hour == 12)
|
|
|
|
tm->tm_hour = 0;
|
|
|
|
buf += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-02-08 17:08:13 +00:00
|
|
|
len = strlen(tptr->pm);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf, tptr->pm, len, locale) == 0) {
|
1997-08-09 15:43:59 +00:00
|
|
|
if (tm->tm_hour > 12)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
if (tm->tm_hour != 12)
|
|
|
|
tm->tm_hour += 12;
|
|
|
|
buf += len;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
case 'A':
|
|
|
|
case 'a':
|
2001-02-08 17:08:13 +00:00
|
|
|
for (i = 0; i < asizeof(tptr->weekday); i++) {
|
2001-03-18 08:41:06 +00:00
|
|
|
len = strlen(tptr->weekday[i]);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf, tptr->weekday[i],
|
|
|
|
len, locale) == 0)
|
2001-03-18 08:41:06 +00:00
|
|
|
break;
|
|
|
|
len = strlen(tptr->wday[i]);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf, tptr->wday[i],
|
|
|
|
len, locale) == 0)
|
2001-03-18 08:41:06 +00:00
|
|
|
break;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
2001-02-08 17:08:13 +00:00
|
|
|
if (i == asizeof(tptr->weekday))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
tm->tm_wday = i;
|
|
|
|
buf += len;
|
|
|
|
break;
|
|
|
|
|
1999-11-10 14:40:59 +00:00
|
|
|
case 'U':
|
|
|
|
case 'W':
|
|
|
|
/*
|
|
|
|
* XXX This is bogus, as we can not assume any valid
|
|
|
|
* information present in the tm structure at this
|
|
|
|
* point to calculate a real value, so just check the
|
|
|
|
* range for now.
|
|
|
|
*/
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-11-10 14:40:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++) {
|
1999-11-10 14:40:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1999-11-10 14:40:59 +00:00
|
|
|
}
|
|
|
|
if (i > 53)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-11-10 14:40:59 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-11-10 14:40:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
i = *buf - '0';
|
1999-11-10 14:40:59 +00:00
|
|
|
if (i > 6)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-11-10 14:40:59 +00:00
|
|
|
|
|
|
|
tm->tm_wday = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
1997-08-09 15:43:59 +00:00
|
|
|
case 'e':
|
1999-12-08 15:49:10 +00:00
|
|
|
/*
|
2014-06-18 23:34:48 +00:00
|
|
|
* With %e format, our strftime(3) adds a blank space
|
|
|
|
* before single digits.
|
|
|
|
*/
|
|
|
|
if (*buf != 0 &&
|
|
|
|
isspace_l((unsigned char)*buf, locale))
|
|
|
|
buf++;
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case 'd':
|
|
|
|
/*
|
|
|
|
* The %e specifier was once explicitly documented as
|
|
|
|
* not being zero-padded but was later changed to
|
|
|
|
* equivalent to %d. There is no harm in allowing
|
1999-12-08 15:49:10 +00:00
|
|
|
* such padding.
|
|
|
|
*
|
|
|
|
* XXX The %e specifier may gobble one too many
|
|
|
|
* digits if used incorrectly.
|
|
|
|
*/
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++) {
|
1997-08-09 15:43:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
|
|
|
if (i > 31)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
tm->tm_mday = i;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'B':
|
|
|
|
case 'b':
|
|
|
|
case 'h':
|
2001-02-08 17:08:13 +00:00
|
|
|
for (i = 0; i < asizeof(tptr->month); i++) {
|
1999-11-30 08:05:09 +00:00
|
|
|
if (Oalternative) {
|
|
|
|
if (c == 'B') {
|
2001-02-08 17:08:13 +00:00
|
|
|
len = strlen(tptr->alt_month[i]);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf,
|
2001-02-08 17:08:13 +00:00
|
|
|
tptr->alt_month[i],
|
2011-11-20 14:45:42 +00:00
|
|
|
len, locale) == 0)
|
1999-11-30 08:05:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2001-03-18 08:41:06 +00:00
|
|
|
len = strlen(tptr->month[i]);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf, tptr->month[i],
|
|
|
|
len, locale) == 0)
|
2001-03-18 08:41:06 +00:00
|
|
|
break;
|
2010-05-09 22:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Try the abbreviated month name if the full name
|
|
|
|
* wasn't found and Oalternative was not requested.
|
|
|
|
*/
|
|
|
|
if (i == asizeof(tptr->month) && !Oalternative) {
|
|
|
|
for (i = 0; i < asizeof(tptr->month); i++) {
|
2001-03-18 08:41:06 +00:00
|
|
|
len = strlen(tptr->mon[i]);
|
2011-11-20 14:45:42 +00:00
|
|
|
if (strncasecmp_l(buf, tptr->mon[i],
|
|
|
|
len, locale) == 0)
|
2001-03-18 08:41:06 +00:00
|
|
|
break;
|
1999-11-30 08:05:09 +00:00
|
|
|
}
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
2001-02-08 17:08:13 +00:00
|
|
|
if (i == asizeof(tptr->month))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
tm->tm_mon = i;
|
|
|
|
buf += len;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++) {
|
1997-08-09 15:43:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
|
|
|
if (i < 1 || i > 12)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
tm->tm_mon = i - 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2001-07-13 13:59:24 +00:00
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
char *cp;
|
2003-11-17 04:19:15 +00:00
|
|
|
int sverrno;
|
|
|
|
long n;
|
2001-07-13 13:59:24 +00:00
|
|
|
time_t t;
|
|
|
|
|
2003-11-17 04:19:15 +00:00
|
|
|
sverrno = errno;
|
|
|
|
errno = 0;
|
2011-11-20 14:45:42 +00:00
|
|
|
n = strtol_l(buf, &cp, 10, locale);
|
2003-11-17 04:19:15 +00:00
|
|
|
if (errno == ERANGE || (long)(t = n) != n) {
|
|
|
|
errno = sverrno;
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
2003-11-17 04:19:15 +00:00
|
|
|
}
|
|
|
|
errno = sverrno;
|
2001-07-13 13:59:24 +00:00
|
|
|
buf = cp;
|
|
|
|
gmtime_r(&t, tm);
|
2003-03-12 19:22:57 +00:00
|
|
|
*GMTp = 1;
|
2001-07-13 13:59:24 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-08-09 15:43:59 +00:00
|
|
|
case 'Y':
|
|
|
|
case 'y':
|
2011-11-20 14:45:42 +00:00
|
|
|
if (*buf == 0 ||
|
|
|
|
isspace_l((unsigned char)*buf, locale))
|
1997-08-09 15:43:59 +00:00
|
|
|
break;
|
|
|
|
|
2011-11-20 14:45:42 +00:00
|
|
|
if (!isdigit_l((unsigned char)*buf, locale))
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-12-08 15:49:10 +00:00
|
|
|
len = (c == 'Y') ? 4 : 2;
|
2011-11-20 14:45:42 +00:00
|
|
|
for (i = 0; len && *buf != 0 &&
|
|
|
|
isdigit_l((unsigned char)*buf, locale); buf++) {
|
1997-08-09 15:43:59 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
1999-12-08 15:49:10 +00:00
|
|
|
len--;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
|
|
|
if (c == 'Y')
|
|
|
|
i -= 1900;
|
1999-04-25 07:28:39 +00:00
|
|
|
if (c == 'y' && i < 69)
|
1999-04-25 01:42:18 +00:00
|
|
|
i += 100;
|
1997-08-09 15:43:59 +00:00
|
|
|
if (i < 0)
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1997-08-09 15:43:59 +00:00
|
|
|
|
|
|
|
tm->tm_year = i;
|
|
|
|
|
|
|
|
break;
|
1999-07-04 08:54:26 +00:00
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
char *zonestr;
|
|
|
|
|
2011-11-20 14:45:42 +00:00
|
|
|
for (cp = buf; *cp &&
|
|
|
|
isupper_l((unsigned char)*cp, locale); ++cp) {
|
|
|
|
/*empty*/}
|
1999-07-04 08:54:26 +00:00
|
|
|
if (cp - buf) {
|
|
|
|
zonestr = alloca(cp - buf + 1);
|
|
|
|
strncpy(zonestr, buf, cp - buf);
|
|
|
|
zonestr[cp - buf] = '\0';
|
|
|
|
tzset();
|
|
|
|
if (0 == strcmp(zonestr, "GMT")) {
|
2003-03-12 19:22:57 +00:00
|
|
|
*GMTp = 1;
|
1999-07-04 08:54:26 +00:00
|
|
|
} else if (0 == strcmp(zonestr, tzname[0])) {
|
1999-07-06 05:05:39 +00:00
|
|
|
tm->tm_isdst = 0;
|
1999-07-04 08:54:26 +00:00
|
|
|
} else if (0 == strcmp(zonestr, tzname[1])) {
|
1999-07-06 05:05:39 +00:00
|
|
|
tm->tm_isdst = 1;
|
1999-07-04 08:54:26 +00:00
|
|
|
} else {
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
1999-07-04 08:54:26 +00:00
|
|
|
}
|
|
|
|
buf += cp - buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2009-06-25 23:59:23 +00:00
|
|
|
|
|
|
|
case 'z':
|
|
|
|
{
|
|
|
|
int sign = 1;
|
|
|
|
|
|
|
|
if (*buf != '+') {
|
|
|
|
if (*buf == '-')
|
|
|
|
sign = -1;
|
|
|
|
else
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
2009-06-25 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buf++;
|
|
|
|
i = 0;
|
|
|
|
for (len = 4; len > 0; len--) {
|
2011-11-20 14:45:42 +00:00
|
|
|
if (isdigit_l((unsigned char)*buf, locale)) {
|
2009-06-25 23:59:23 +00:00
|
|
|
i *= 10;
|
|
|
|
i += *buf - '0';
|
|
|
|
buf++;
|
|
|
|
} else
|
2014-06-18 02:36:21 +00:00
|
|
|
return (NULL);
|
2009-06-25 23:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tm->tm_hour -= sign * (i / 100);
|
|
|
|
tm->tm_min -= sign * (i % 100);
|
|
|
|
*GMTp = 1;
|
|
|
|
}
|
|
|
|
break;
|
2014-06-18 23:34:48 +00:00
|
|
|
|
|
|
|
case 'n':
|
|
|
|
case 't':
|
|
|
|
while (isspace_l((unsigned char)*buf, locale))
|
|
|
|
buf++;
|
|
|
|
break;
|
1997-08-09 15:43:59 +00:00
|
|
|
}
|
|
|
|
}
|
2014-06-18 02:36:21 +00:00
|
|
|
return ((char *)buf);
|
1999-07-06 05:05:39 +00:00
|
|
|
}
|
|
|
|
|
1997-08-09 15:43:59 +00:00
|
|
|
|
1999-07-06 05:05:39 +00:00
|
|
|
char *
|
2011-11-20 14:45:42 +00:00
|
|
|
strptime_l(const char * __restrict buf, const char * __restrict fmt,
|
|
|
|
struct tm * __restrict tm, locale_t loc)
|
1999-07-06 05:05:39 +00:00
|
|
|
{
|
|
|
|
char *ret;
|
2003-03-12 19:22:57 +00:00
|
|
|
int gmt;
|
2011-11-20 14:45:42 +00:00
|
|
|
FIX_LOCALE(loc);
|
1999-07-06 05:05:39 +00:00
|
|
|
|
2003-03-12 19:22:57 +00:00
|
|
|
gmt = 0;
|
2011-11-20 14:45:42 +00:00
|
|
|
ret = _strptime(buf, fmt, tm, &gmt, loc);
|
2003-04-30 10:25:57 +00:00
|
|
|
if (ret && gmt) {
|
|
|
|
time_t t = timegm(tm);
|
2001-01-24 13:01:12 +00:00
|
|
|
localtime_r(&t, tm);
|
1999-07-04 08:54:26 +00:00
|
|
|
}
|
1999-07-06 05:05:39 +00:00
|
|
|
|
2003-03-12 19:22:57 +00:00
|
|
|
return (ret);
|
1997-08-09 15:38:14 +00:00
|
|
|
}
|
2011-11-20 14:45:42 +00:00
|
|
|
char *
|
|
|
|
strptime(const char * __restrict buf, const char * __restrict fmt,
|
|
|
|
struct tm * __restrict tm)
|
|
|
|
{
|
|
|
|
return strptime_l(buf, fmt, tm, __get_locale());
|
|
|
|
}
|