summaryrefslogtreecommitdiffstats
path: root/newlib/libc/time/strptime.c
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2010-01-22 13:03:42 +0000
committerCorinna Vinschen <corinna@vinschen.de>2010-01-22 13:03:42 +0000
commitfe57329f991a0b347d40a5c97d9a62285eb708fe (patch)
tree4e6a2b000d865212b1d854c9d0ce8b1f0e0d5e88 /newlib/libc/time/strptime.c
parent2d7f21da1e428214d8a18e3ebea9e822586b516f (diff)
downloadcygnal-fe57329f991a0b347d40a5c97d9a62285eb708fe.tar.gz
cygnal-fe57329f991a0b347d40a5c97d9a62285eb708fe.tar.bz2
cygnal-fe57329f991a0b347d40a5c97d9a62285eb708fe.zip
* libc/locale/lmonetary.c (__monetary_load_locale): Take additional
parameters for wide char to multibyte conversion. Call __set_lc_monetary_from_win on Cygwin. * libc/locale/lmonetary.h: Make C++-safe. (__monetary_load_locale): Change declaration. * libc/locale/lnumeric.c (__numeric_load_locale): Take additional parameters for wide char to multibyte conversion. Call __set_lc_numeric_from_win on Cygwin. * libc/locale/lnumeric.h: Make C++-safe. (__numeric_load_locale): Change declaration. * libc/locale/locale.c (lconv): De-constify for Cygwin. (__set_charset_from_locale): Rename from __set_charset_from_codepage. Take locale as parameter instead of a codepage. (loadlocale): Allow "EUC-JP" for "EUCJP" and "EUC-KR" for "EUCKR". Change documnetation accordingly. Enable LC_COLLATE, LC_MONETARY, LC_NUMERIC, and LC_TIME handling on Cygwin. (_localeconv_r): On Cygwin, copy values from monetary and numeric domain if change has been noted. * libc/locale/nl_langinfo.c (nl_langinfo): Accommodate change of am/pm layout in struct lc_time_T. * libc/locale/timelocal.c (_C_time_locale): Accommodate redefinition of am/pm members. (__time_load_locale): Take additional parameters for wide char to multibyte conversion. Call __set_lc_time_from_win on Cygwin. * libc/locale/timelocal.h: Make C++-safe. (struct lc_time_T): Convert am and pm to a am_pm array for easier consumption by strftime and strptime. (__time_load_locale): Change declaration. * libc/time/strftime.c: Change documentation to reflect changes to strftime. Remove locale constant strings in favor of access to locale-specifc data. (_ctloc): Define access method for locale-specifc data. (TOLOWER): Define for tolower conversion. (strftime): Throughout, convert locale-specific formats to use locale-specific data. Add GNU-specific "%P" format. * libc/time/strptime.c: Remove locale constant strings in favor of access to locale-specifc data. (_ctloc): Define access method for locale-specifc data. (strptime): Throughout, convert locale-specific formats to use locale-specific data.
Diffstat (limited to 'newlib/libc/time/strptime.c')
-rw-r--r--newlib/libc/time/strptime.c85
1 files changed, 17 insertions, 68 deletions
diff --git a/newlib/libc/time/strptime.c b/newlib/libc/time/strptime.c
index 127772460..1457c93ed 100644
--- a/newlib/libc/time/strptime.c
+++ b/newlib/libc/time/strptime.c
@@ -36,66 +36,9 @@
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
+#include "../locale/timelocal.h"
-static const char *abb_weekdays[] = {
- "Sun",
- "Mon",
- "Tue",
- "Wed",
- "Thu",
- "Fri",
- "Sat",
- NULL
-};
-
-static const char *full_weekdays[] = {
- "Sunday",
- "Monday",
- "Tuesday",
- "Wednesday",
- "Thursday",
- "Friday",
- "Saturday",
- NULL
-};
-
-static const char *abb_month[] = {
- "Jan",
- "Feb",
- "Mar",
- "Apr",
- "May",
- "Jun",
- "Jul",
- "Aug",
- "Sep",
- "Oct",
- "Nov",
- "Dec",
- NULL
-};
-
-static const char *full_month[] = {
- "January",
- "February",
- "March",
- "April",
- "May",
- "June",
- "July",
- "August",
- "September",
- "October",
- "November",
- "December",
- NULL,
-};
-
-static const char *ampm[] = {
- "am",
- "pm",
- NULL
-};
+#define _ctloc(x) (_CurrentTimeLocale->x)
/*
* tm_year is relative this year
@@ -205,6 +148,7 @@ _DEFUN (strptime, (buf, format, timeptr),
{
char c;
+ struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale ();
for (; (c = *format) != '\0'; ++format) {
char *s;
int ret;
@@ -218,26 +162,26 @@ _DEFUN (strptime, (buf, format, timeptr),
c = *++format;
switch (c) {
case 'A' :
- ret = match_string (&buf, full_weekdays);
+ ret = match_string (&buf, _ctloc (weekday));
if (ret < 0)
return NULL;
timeptr->tm_wday = ret;
break;
case 'a' :
- ret = match_string (&buf, abb_weekdays);
+ ret = match_string (&buf, _ctloc (wday));
if (ret < 0)
return NULL;
timeptr->tm_wday = ret;
break;
case 'B' :
- ret = match_string (&buf, full_month);
+ ret = match_string (&buf, _ctloc (month));
if (ret < 0)
return NULL;
timeptr->tm_mon = ret;
break;
case 'b' :
case 'h' :
- ret = match_string (&buf, abb_month);
+ ret = match_string (&buf, _ctloc (mon));
if (ret < 0)
return NULL;
timeptr->tm_mon = ret;
@@ -250,7 +194,7 @@ _DEFUN (strptime, (buf, format, timeptr),
buf = s;
break;
case 'c' : /* %a %b %e %H:%M:%S %Y */
- s = strptime (buf, "%a %b %e %H:%M:%S %Y", timeptr);
+ s = strptime (buf, _ctloc (c_fmt), timeptr);
if (s == NULL)
return NULL;
buf = s;
@@ -316,7 +260,7 @@ _DEFUN (strptime, (buf, format, timeptr),
return NULL;
break;
case 'p' :
- ret = match_string (&buf, ampm);
+ ret = match_string (&buf, _ctloc (am_pm));
if (ret < 0)
return NULL;
if (timeptr->tm_hour == 0) {
@@ -326,7 +270,7 @@ _DEFUN (strptime, (buf, format, timeptr),
timeptr->tm_hour += 12;
break;
case 'r' : /* %I:%M:%S %p */
- s = strptime (buf, "%I:%M:%S %p", timeptr);
+ s = strptime (buf, _ctloc (ampm_fmt), timeptr);
if (s == NULL)
return NULL;
buf = s;
@@ -351,7 +295,6 @@ _DEFUN (strptime, (buf, format, timeptr),
return NULL;
break;
case 'T' : /* %H:%M:%S */
- case 'X' :
s = strptime (buf, "%H:%M:%S", timeptr);
if (s == NULL)
return NULL;
@@ -393,11 +336,17 @@ _DEFUN (strptime, (buf, format, timeptr),
buf = s;
break;
case 'x' :
- s = strptime (buf, "%Y:%m:%d", timeptr);
+ s = strptime (buf, _ctloc (x_fmt), timeptr);
if (s == NULL)
return NULL;
buf = s;
break;
+ case 'X' :
+ s = strptime (buf, _ctloc (X_fmt), timeptr);
+ if (s == NULL)
+ return NULL;
+ buf = s;
+ break;
case 'y' :
ret = strtol (buf, &s, 10);
if (s == buf)