mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 10:50:07 +00:00
Update.
* time/strptime.c (strptime_internal): Set tm_wday and tm_yday in any of tm_year, tm_mon, or tm_mday was changed and the value itself wasn't specified.
This commit is contained in:
parent
2eda5d9bb3
commit
c2cfb5126b
@ -1,5 +1,9 @@
|
|||||||
1998-12-14 Ulrich Drepper <drepper@cygnus.com>
|
1998-12-14 Ulrich Drepper <drepper@cygnus.com>
|
||||||
|
|
||||||
|
* time/strptime.c (strptime_internal): Set tm_wday and tm_yday in
|
||||||
|
any of tm_year, tm_mon, or tm_mday was changed and the value
|
||||||
|
itself wasn't specified.
|
||||||
|
|
||||||
* include/stdio.h: Add new parameter to __path_search.
|
* include/stdio.h: Add new parameter to __path_search.
|
||||||
* libio/oldtmpfile.c: Add 0 as new parameter to __path_search.
|
* libio/oldtmpfile.c: Add 0 as new parameter to __path_search.
|
||||||
* stdio-common/tmpfile.c: Likewise.
|
* stdio-common/tmpfile.c: Likewise.
|
||||||
|
@ -46,12 +46,13 @@
|
|||||||
# endif /* GCC. */
|
# endif /* GCC. */
|
||||||
#endif /* Not __P. */
|
#endif /* Not __P. */
|
||||||
|
|
||||||
#if ! HAVE_LOCALTIME_R && ! defined (localtime_r)
|
|
||||||
#ifdef _LIBC
|
#if ! HAVE_LOCALTIME_R && ! defined localtime_r
|
||||||
#define localtime_r __localtime_r
|
# ifdef _LIBC
|
||||||
#else
|
# define localtime_r __localtime_r
|
||||||
|
# else
|
||||||
/* Approximate localtime_r as best we can in its absence. */
|
/* Approximate localtime_r as best we can in its absence. */
|
||||||
#define localtime_r my_localtime_r
|
# define localtime_r my_localtime_r
|
||||||
static struct tm *localtime_r __P ((const time_t *, struct tm *));
|
static struct tm *localtime_r __P ((const time_t *, struct tm *));
|
||||||
static struct tm *
|
static struct tm *
|
||||||
localtime_r (t, tp)
|
localtime_r (t, tp)
|
||||||
@ -64,7 +65,7 @@ localtime_r (t, tp)
|
|||||||
*tp = *l;
|
*tp = *l;
|
||||||
return tp;
|
return tp;
|
||||||
}
|
}
|
||||||
#endif /* ! _LIBC */
|
# endif /* ! _LIBC */
|
||||||
#endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
|
#endif /* ! HAVE_LOCALTIME_R && ! defined (localtime_r) */
|
||||||
|
|
||||||
|
|
||||||
@ -135,6 +136,7 @@ localtime_r (t, tp)
|
|||||||
#ifdef _LIBC
|
#ifdef _LIBC
|
||||||
/* This is defined in locale/C-time.c in the GNU libc. */
|
/* This is defined in locale/C-time.c in the GNU libc. */
|
||||||
extern const struct locale_data _nl_C_LC_TIME;
|
extern const struct locale_data _nl_C_LC_TIME;
|
||||||
|
extern const unsigned short int __mon_yday[2][13];
|
||||||
|
|
||||||
# define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string)
|
# define weekday_name (&_nl_C_LC_TIME.values[_NL_ITEM_INDEX (DAY_1)].string)
|
||||||
# define ab_weekday_name \
|
# define ab_weekday_name \
|
||||||
@ -176,11 +178,51 @@ static char const ab_month_name[][4] =
|
|||||||
# define HERE_PM_STR "PM"
|
# define HERE_PM_STR "PM"
|
||||||
# define HERE_T_FMT_AMPM "%I:%M:%S %p"
|
# define HERE_T_FMT_AMPM "%I:%M:%S %p"
|
||||||
# define HERE_T_FMT "%H:%M:%S"
|
# define HERE_T_FMT "%H:%M:%S"
|
||||||
|
|
||||||
|
const unsigned short int __mon_yday[1][13] =
|
||||||
|
{
|
||||||
|
/* Normal years. */
|
||||||
|
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
|
||||||
|
/* Leap years. */
|
||||||
|
{ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Status of lookup: do we use the locale data or the raw data? */
|
/* Status of lookup: do we use the locale data or the raw data? */
|
||||||
enum locale_status { not, loc, raw };
|
enum locale_status { not, loc, raw };
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __isleap
|
||||||
|
/* Nonzero if YEAR is a leap year (every 4 years,
|
||||||
|
except every 100th isn't, and every 400th is). */
|
||||||
|
# define __isleap(year) \
|
||||||
|
((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Compute the day of the week. */
|
||||||
|
static void
|
||||||
|
day_of_the_week (struct tm *tm)
|
||||||
|
{
|
||||||
|
/* We know that January 1st 1970 was a Thursday (= 4). Compute the
|
||||||
|
the difference between this data in the one on TM and so determine
|
||||||
|
the weekday. */
|
||||||
|
int corr_year = tm->tm_mon >= 2 ? tm->tm_year : tm->tm_year - 1;
|
||||||
|
int wday = (-473
|
||||||
|
+ (365 * (tm->tm_year - 1970))
|
||||||
|
+ (corr_year / 4)
|
||||||
|
- ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0)
|
||||||
|
+ (((corr_year / 4) / 25) / 4)
|
||||||
|
+ __mon_yday[0][tm->tm_mon]
|
||||||
|
+ tm->tm_mday);
|
||||||
|
tm->tm_wday = wday;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
day_of_the_year (struct tm *tm)
|
||||||
|
{
|
||||||
|
tm->tm_yday = __mon_yday[__isleap (tm->tm_year)][tm->tm_mon] + tm->tm_mday;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
#ifdef _LIBC
|
#ifdef _LIBC
|
||||||
internal_function
|
internal_function
|
||||||
@ -204,12 +246,15 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
size_t val;
|
size_t val;
|
||||||
int have_I, is_pm;
|
int have_I, is_pm;
|
||||||
int century, want_century;
|
int century, want_century;
|
||||||
|
int have_wday, want_xday;
|
||||||
|
int have_yday;
|
||||||
|
|
||||||
rp = buf;
|
rp = buf;
|
||||||
fmt = format;
|
fmt = format;
|
||||||
have_I = is_pm = 0;
|
have_I = is_pm = 0;
|
||||||
century = -1;
|
century = -1;
|
||||||
want_century = 0;
|
want_century = 0;
|
||||||
|
have_wday = want_xday = have_yday = 0;
|
||||||
|
|
||||||
while (*fmt != '\0')
|
while (*fmt != '\0')
|
||||||
{
|
{
|
||||||
@ -280,6 +325,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Does not match a weekday name. */
|
/* Does not match a weekday name. */
|
||||||
return NULL;
|
return NULL;
|
||||||
tm->tm_wday = cnt;
|
tm->tm_wday = cnt;
|
||||||
|
have_wday = 1;
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'B':
|
case 'B':
|
||||||
@ -319,6 +365,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Does not match a month name. */
|
/* Does not match a month name. */
|
||||||
return NULL;
|
return NULL;
|
||||||
tm->tm_mon = cnt;
|
tm->tm_mon = cnt;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
/* Match locale's date and time format. */
|
/* Match locale's date and time format. */
|
||||||
@ -335,6 +382,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
if (*decided == not &&
|
if (*decided == not &&
|
||||||
strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT))
|
strcmp (_NL_CURRENT (LC_TIME, D_T_FMT), HERE_D_T_FMT))
|
||||||
*decided = loc;
|
*decided = loc;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*decided = raw;
|
*decided = raw;
|
||||||
@ -342,11 +390,13 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
#endif
|
#endif
|
||||||
if (!recursive (HERE_D_T_FMT))
|
if (!recursive (HERE_D_T_FMT))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
/* Match century number. */
|
/* Match century number. */
|
||||||
get_number (0, 99);
|
get_number (0, 99);
|
||||||
century = val;
|
century = val;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
case 'e':
|
case 'e':
|
||||||
@ -368,6 +418,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
if (decided == not
|
if (decided == not
|
||||||
&& strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT))
|
&& strcmp (_NL_CURRENT (LC_TIME, D_FMT), HERE_D_FMT))
|
||||||
*decided = loc;
|
*decided = loc;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*decided = raw;
|
*decided = raw;
|
||||||
@ -378,6 +429,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Match standard day format. */
|
/* Match standard day format. */
|
||||||
if (!recursive (HERE_D_FMT))
|
if (!recursive (HERE_D_FMT))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
/* Match hour in 24-hour clock. */
|
/* Match hour in 24-hour clock. */
|
||||||
@ -395,11 +447,13 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Match day number of year. */
|
/* Match day number of year. */
|
||||||
get_number (1, 366);
|
get_number (1, 366);
|
||||||
tm->tm_yday = val - 1;
|
tm->tm_yday = val - 1;
|
||||||
|
have_yday = 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
/* Match number of month. */
|
/* Match number of month. */
|
||||||
get_number (1, 12);
|
get_number (1, 12);
|
||||||
tm->tm_mon = val - 1;
|
tm->tm_mon = val - 1;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
/* Match minute. */
|
/* Match minute. */
|
||||||
@ -519,6 +573,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
case 'u':
|
case 'u':
|
||||||
get_number (1, 7);
|
get_number (1, 7);
|
||||||
tm->tm_wday = val % 7;
|
tm->tm_wday = val % 7;
|
||||||
|
have_wday = 1;
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
get_number (0, 99);
|
get_number (0, 99);
|
||||||
@ -544,6 +599,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Match number of weekday. */
|
/* Match number of weekday. */
|
||||||
get_number (0, 6);
|
get_number (0, 6);
|
||||||
tm->tm_wday = val;
|
tm->tm_wday = val;
|
||||||
|
have_wday = 1;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
/* Match year within century. */
|
/* Match year within century. */
|
||||||
@ -553,12 +609,14 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
tm->tm_year = val >= 69 ? val : val + 100;
|
tm->tm_year = val >= 69 ? val : val + 100;
|
||||||
/* Indicate that we want to use the century, if specified. */
|
/* Indicate that we want to use the century, if specified. */
|
||||||
want_century = 1;
|
want_century = 1;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'Y':
|
case 'Y':
|
||||||
/* Match year including century number. */
|
/* Match year including century number. */
|
||||||
get_number (0, 9999);
|
get_number (0, 9999);
|
||||||
tm->tm_year = val - 1900;
|
tm->tm_year = val - 1900;
|
||||||
want_century = 0;
|
want_century = 0;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'Z':
|
case 'Z':
|
||||||
/* XXX How to handle this? */
|
/* XXX How to handle this? */
|
||||||
@ -585,6 +643,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
{
|
{
|
||||||
if (strcmp (fmt, HERE_D_T_FMT))
|
if (strcmp (fmt, HERE_D_T_FMT))
|
||||||
*decided = loc;
|
*decided = loc;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
*decided = raw;
|
*decided = raw;
|
||||||
@ -593,6 +652,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
normal representation. */
|
normal representation. */
|
||||||
if (!recursive (HERE_D_T_FMT))
|
if (!recursive (HERE_D_T_FMT))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'y':
|
case 'y':
|
||||||
@ -672,6 +732,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Match day of month using alternate numeric symbols. */
|
/* Match day of month using alternate numeric symbols. */
|
||||||
get_alt_number (1, 31);
|
get_alt_number (1, 31);
|
||||||
tm->tm_mday = val;
|
tm->tm_mday = val;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
/* Match hour in 24-hour clock using alternate numeric
|
/* Match hour in 24-hour clock using alternate numeric
|
||||||
@ -691,6 +752,7 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Match month using alternate numeric symbols. */
|
/* Match month using alternate numeric symbols. */
|
||||||
get_alt_number (1, 12);
|
get_alt_number (1, 12);
|
||||||
tm->tm_mon = val - 1;
|
tm->tm_mon = val - 1;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
case 'M':
|
case 'M':
|
||||||
/* Match minutes using alternate numeric symbols. */
|
/* Match minutes using alternate numeric symbols. */
|
||||||
@ -713,11 +775,13 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
/* Match number of weekday using alternate numeric symbols. */
|
/* Match number of weekday using alternate numeric symbols. */
|
||||||
get_alt_number (0, 6);
|
get_alt_number (0, 6);
|
||||||
tm->tm_wday = val;
|
tm->tm_wday = val;
|
||||||
|
have_wday = 1;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
/* Match year within century using alternate numeric symbols. */
|
/* Match year within century using alternate numeric symbols. */
|
||||||
get_alt_number (0, 99);
|
get_alt_number (0, 99);
|
||||||
tm->tm_year = val >= 69 ? val : val + 100;
|
tm->tm_year = val >= 69 ? val : val + 100;
|
||||||
|
want_xday = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -734,6 +798,11 @@ strptime_internal (buf, format, tm, decided)
|
|||||||
if (want_century && century != -1)
|
if (want_century && century != -1)
|
||||||
tm->tm_year = tm->tm_year % 100 + (century - 19) * 100;
|
tm->tm_year = tm->tm_year % 100 + (century - 19) * 100;
|
||||||
|
|
||||||
|
if (want_xday && !have_wday)
|
||||||
|
day_of_the_week (tm);
|
||||||
|
if (want_xday && !have_yday)
|
||||||
|
day_of_the_year (tm);
|
||||||
|
|
||||||
return (char *) rp;
|
return (char *) rp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user