FreeBSD Bugzilla – Attachment 144894 Details for
Bug 137307
[libc] [patch] Enhance strptime(3) to support %U and %W
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Updated libc patch
libc-strptime.diff (text/plain), 2.92 KB, created by
Pedro F. Giffuni
on 2014-07-22 21:39:36 UTC
(
hide
)
Description:
Updated libc patch
Filename:
MIME Type:
Creator:
Pedro F. Giffuni
Created:
2014-07-22 21:39:36 UTC
Size:
2.92 KB
patch
obsolete
>Index: lib/libc/stdtime/strptime.3 >=================================================================== >--- lib/libc/stdtime/strptime.3 (revision 268982) >+++ lib/libc/stdtime/strptime.3 (working copy) >@@ -164,9 +164,7 @@ > .Fa \&%U > and > .Fa %W >-format specifiers accept any value within the range 00 to 53 >-without validating against other values supplied (like month >-or day of the year, for example). >+format specifiers accept a two-digit decimal within the range 00 to 53. > .Pp > The > .Fa %Z >Index: lib/libc/stdtime/strptime.c >=================================================================== >--- lib/libc/stdtime/strptime.c (revision 268982) >+++ lib/libc/stdtime/strptime.c (working copy) >@@ -56,10 +56,20 @@ > #include "libc_private.h" > #include "timelocal.h" > >+#include "tzfile.h" >+ > static char * _strptime(const char *, const char *, struct tm *, int *, locale_t); > >-#define asizeof(a) (sizeof (a) / sizeof ((a)[0])) >+#define asizeof(a) (sizeof(a) / sizeof((a)[0])) > >+static int >+first_wday_of(int year) >+{ >+ return (((2 * (3 - (year / 100) % 4)) + (year % 100) + >+ ((year % 100) / 4) + (isleap(year) ? 6 : 0) + 1) % 7); >+} >+ >+ > static char * > _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp, > locale_t locale) >@@ -66,9 +76,12 @@ > { > char c; > const char *ptr; >- int i, len; >+ int day_offset, i, len; > int Ealternative, Oalternative; > struct lc_time_T *tptr = __get_current_time_locale(locale); >+ static int start_of_month[2][13] = { >+ {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, >+ {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366}}; > > ptr = fmt; > while (*ptr != 0) { >@@ -309,10 +322,8 @@ > 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. >+ * We expect that the year has already been >+ * parsed. > */ > if (!isdigit_l((unsigned char)*buf, locale)) > return (NULL); >@@ -327,6 +338,42 @@ > if (i > 53) > return (NULL); > >+ /* Week numbers are 1-origin. So that we can always >+ * return the date of a Sunday (or Monday), treat week >+ * 0 as week 1. >+ */ >+ >+ if (i == 0) >+ i = 1; >+ >+ if (c == 'U') >+ day_offset = 0; /* Sunday */ >+ else day_offset = 1; /* Monday */ >+ >+ /* >+ * Set the date to the first Sunday (or Monday) >+ * of the specified week of the year. >+ */ >+ >+ tm->tm_yday = (7 - first_wday_of(tm->tm_year + 1900) + >+ day_offset) % 7 + (i-1) * 7; >+ i = 0; >+ while (tm->tm_yday >= >+ start_of_month[isleap(tm->tm_year + 1900)][i]) >+ i++; >+ if (i > 12) >+ { >+ i = 1; >+ tm->tm_yday -= >+ start_of_month[ >+ isleap(tm->tm_year + 1900)][12]; >+ tm->tm_year++; >+ } >+ tm->tm_mon = i - 1; >+ tm->tm_mday = tm->tm_yday - >+ start_of_month[isleap(tm->tm_year+1900)][i - 1] + 1; >+ tm->tm_wday = day_offset; >+ > break; > > case 'w':
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 137307
:
98401
|
98402
|
144894
|
145108
|
145481
|
145482
|
147573
|
147680
|
147740