[Midnightbsd-cvs] src [10528] trunk/lib/libc/stdtime/timelocal.c: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Thu Jun 7 18:53:14 EDT 2018
Revision: 10528
http://svnweb.midnightbsd.org/src/?rev=10528
Author: laffer1
Date: 2018-06-07 18:53:14 -0400 (Thu, 07 Jun 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/lib/libc/stdtime/strftime.3
trunk/lib/libc/stdtime/strftime.c
trunk/lib/libc/stdtime/strptime.3
trunk/lib/libc/stdtime/strptime.c
trunk/lib/libc/stdtime/timelocal.c
Property Changed:
----------------
trunk/lib/libc/stdtime/Makefile.inc
trunk/lib/libc/stdtime/Symbol.map
trunk/lib/libc/stdtime/strftime.3
trunk/lib/libc/stdtime/strptime.3
Index: trunk/lib/libc/stdtime/Makefile.inc
===================================================================
--- trunk/lib/libc/stdtime/Makefile.inc 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/Makefile.inc 2018-06-07 22:53:14 UTC (rev 10528)
Property changes on: trunk/lib/libc/stdtime/Makefile.inc
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Index: trunk/lib/libc/stdtime/Symbol.map
===================================================================
--- trunk/lib/libc/stdtime/Symbol.map 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/Symbol.map 2018-06-07 22:53:14 UTC (rev 10528)
Property changes on: trunk/lib/libc/stdtime/Symbol.map
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdtime/strftime.3
===================================================================
--- trunk/lib/libc/stdtime/strftime.3 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/strftime.3 2018-06-07 22:53:14 UTC (rev 10528)
@@ -30,6 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93
+.\" $FreeBSD: stable/10/lib/libc/stdtime/strftime.3 268721 2014-07-15 22:44:10Z wblock $
.\" $MidnightBSD$
.\"
.Dd June 25, 2012
@@ -248,7 +249,7 @@
conforms to
.St -isoC
with a lot of extensions including
-.Ql %C ,
+.Ql \&%C ,
.Ql \&%D ,
.Ql %E* ,
.Ql %e ,
Property changes on: trunk/lib/libc/stdtime/strftime.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdtime/strftime.c
===================================================================
--- trunk/lib/libc/stdtime/strftime.c 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/strftime.c 2018-06-07 22:53:14 UTC (rev 10528)
@@ -24,9 +24,9 @@
#ifndef NOID
static const char elsieid[] = "@(#)strftime.3 8.3";
/*
-** Based on the UCB version with the ID appearing below.
-** This is ANSIish only when "multibyte character == plain character".
-*/
+ * Based on the UCB version with the ID appearing below.
+ * This is ANSIish only when "multibyte character == plain character".
+ */
#endif /* !defined NOID */
#endif /* !defined lint */
@@ -46,10 +46,10 @@
#include "timelocal.h"
static char * _add(const char *, char *, const char *);
-static char * _conv(int, const char *, char *, const char *);
+static char * _conv(int, const char *, char *, const char *, locale_t);
static char * _fmt(const char *, const struct tm *, char *, const char *,
int *, locale_t);
-static char * _yconv(int, int, int, int, char *, const char *);
+static char * _yconv(int, int, int, int, char *, const char *, locale_t);
extern char * tzname[];
@@ -57,32 +57,32 @@
#define YEAR_2000_NAME "CHECK_STRFTIME_FORMATS_FOR_TWO_DIGIT_YEARS"
#endif /* !defined YEAR_2000_NAME */
-#define IN_NONE 0
-#define IN_SOME 1
-#define IN_THIS 2
-#define IN_ALL 3
+#define IN_NONE 0
+#define IN_SOME 1
+#define IN_THIS 2
+#define IN_ALL 3
-#define PAD_DEFAULT 0
-#define PAD_LESS 1
-#define PAD_SPACE 2
-#define PAD_ZERO 3
+#define PAD_DEFAULT 0
+#define PAD_LESS 1
+#define PAD_SPACE 2
+#define PAD_ZERO 3
-static const char* fmt_padding[][4] = {
+static const char fmt_padding[][4][5] = {
/* DEFAULT, LESS, SPACE, ZERO */
-#define PAD_FMT_MONTHDAY 0
-#define PAD_FMT_HMS 0
-#define PAD_FMT_CENTURY 0
-#define PAD_FMT_SHORTYEAR 0
-#define PAD_FMT_MONTH 0
-#define PAD_FMT_WEEKOFYEAR 0
-#define PAD_FMT_DAYOFMONTH 0
+#define PAD_FMT_MONTHDAY 0
+#define PAD_FMT_HMS 0
+#define PAD_FMT_CENTURY 0
+#define PAD_FMT_SHORTYEAR 0
+#define PAD_FMT_MONTH 0
+#define PAD_FMT_WEEKOFYEAR 0
+#define PAD_FMT_DAYOFMONTH 0
{ "%02d", "%d", "%2d", "%02d" },
-#define PAD_FMT_SDAYOFMONTH 1
-#define PAD_FMT_SHMS 1
+#define PAD_FMT_SDAYOFMONTH 1
+#define PAD_FMT_SHMS 1
{ "%2d", "%d", "%2d", "%02d" },
#define PAD_FMT_DAYOFYEAR 2
{ "%03d", "%d", "%3d", "%03d" },
-#define PAD_FMT_YEAR 3
+#define PAD_FMT_YEAR 3
{ "%04d", "%d", "%4d", "%04d" }
};
@@ -101,20 +101,20 @@
if (warn != IN_NONE && getenv(YEAR_2000_NAME) != NULL) {
(void) fprintf_l(stderr, loc, "\n");
if (format == NULL)
- (void) fprintf_l(stderr, loc, "NULL strftime format ");
+ (void) fputs("NULL strftime format ", stderr);
else (void) fprintf_l(stderr, loc, "strftime format \"%s\" ",
format);
- (void) fprintf_l(stderr, loc, "yields only two digits of years in ");
+ (void) fputs("yields only two digits of years in ", stderr);
if (warn == IN_SOME)
- (void) fprintf_l(stderr, loc, "some locales");
+ (void) fputs("some locales", stderr);
else if (warn == IN_THIS)
- (void) fprintf_l(stderr, loc, "the current locale");
- else (void) fprintf_l(stderr, loc, "all locales");
- (void) fprintf_l(stderr, loc, "\n");
+ (void) fputs("the current locale", stderr);
+ else (void) fputs("all locales", stderr);
+ (void) fputs("\n", stderr);
}
#endif /* !defined NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU */
if (p == s + maxsize)
- return 0;
+ return (0);
*p = '\0';
return p - s;
}
@@ -176,14 +176,14 @@
continue;
case 'C':
/*
- ** %C used to do a...
- ** _fmt("%a %b %e %X %Y", t);
- ** ...whereas now POSIX 1003.2 calls for
- ** something completely different.
- ** (ado, 1993-05-24)
- */
+ * %C used to do a...
+ * _fmt("%a %b %e %X %Y", t);
+ * ...whereas now POSIX 1003.2 calls for
+ * something completely different.
+ * (ado, 1993-05-24)
+ */
pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 0,
- pt, ptlim);
+ pt, ptlim, loc);
continue;
case 'c':
{
@@ -200,8 +200,9 @@
pt = _fmt("%m/%d/%y", t, pt, ptlim, warnp, loc);
continue;
case 'd':
- pt = _conv(t->tm_mday, fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex],
- pt, ptlim);
+ pt = _conv(t->tm_mday,
+ fmt_padding[PAD_FMT_DAYOFMONTH][PadIndex],
+ pt, ptlim, loc);
continue;
case 'E':
if (Ealternative || Oalternative)
@@ -210,17 +211,17 @@
goto label;
case 'O':
/*
- ** C99 locale modifiers.
- ** The sequences
- ** %Ec %EC %Ex %EX %Ey %EY
- ** %Od %oe %OH %OI %Om %OM
- ** %OS %Ou %OU %OV %Ow %OW %Oy
- ** are supposed to provide alternate
- ** representations.
- **
- ** FreeBSD extension
- ** %OB
- */
+ * C99 locale modifiers.
+ * The sequences
+ * %Ec %EC %Ex %EX %Ey %EY
+ * %Od %oe %OH %OI %Om %OM
+ * %OS %Ou %OU %OV %Ow %OW %Oy
+ * are supposed to provide alternate
+ * representations.
+ *
+ * FreeBSD extension
+ * %OB
+ */
if (Ealternative || Oalternative)
break;
Oalternative++;
@@ -227,7 +228,8 @@
goto label;
case 'e':
pt = _conv(t->tm_mday,
- fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_SDAYOFMONTH][PadIndex],
+ pt, ptlim, loc);
continue;
case 'F':
pt = _fmt("%Y-%m-%d", t, pt, ptlim, warnp, loc);
@@ -234,30 +236,32 @@
continue;
case 'H':
pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_HMS][PadIndex],
- pt, ptlim);
+ pt, ptlim, loc);
continue;
case 'I':
pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12,
- fmt_padding[PAD_FMT_HMS][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_HMS][PadIndex],
+ pt, ptlim, loc);
continue;
case 'j':
pt = _conv(t->tm_yday + 1,
- fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_DAYOFYEAR][PadIndex],
+ pt, ptlim, loc);
continue;
case 'k':
/*
- ** This used to be...
- ** _conv(t->tm_hour % 12 ?
- ** t->tm_hour % 12 : 12, 2, ' ');
- ** ...and has been changed to the below to
- ** match SunOS 4.1.1 and Arnold Robbins'
- ** strftime version 3.0. That is, "%k" and
- ** "%l" have been swapped.
- ** (ado, 1993-05-24)
- */
+ * This used to be...
+ * _conv(t->tm_hour % 12 ?
+ * t->tm_hour % 12 : 12, 2, ' ');
+ * ...and has been changed to the below to
+ * match SunOS 4.1.1 and Arnold Robbins'
+ * strftime version 3.0. That is, "%k" and
+ * "%l" have been swapped.
+ * (ado, 1993-05-24)
+ */
pt = _conv(t->tm_hour, fmt_padding[PAD_FMT_SHMS][PadIndex],
- pt, ptlim);
+ pt, ptlim, loc);
continue;
#ifdef KITCHEN_SINK
case 'K':
@@ -269,25 +273,27 @@
#endif /* defined KITCHEN_SINK */
case 'l':
/*
- ** This used to be...
- ** _conv(t->tm_hour, 2, ' ');
- ** ...and has been changed to the below to
- ** match SunOS 4.1.1 and Arnold Robbin's
- ** strftime version 3.0. That is, "%k" and
- ** "%l" have been swapped.
- ** (ado, 1993-05-24)
- */
+ * This used to be...
+ * _conv(t->tm_hour, 2, ' ');
+ * ...and has been changed to the below to
+ * match SunOS 4.1.1 and Arnold Robbin's
+ * strftime version 3.0. That is, "%k" and
+ * "%l" have been swapped.
+ * (ado, 1993-05-24)
+ */
pt = _conv((t->tm_hour % 12) ?
(t->tm_hour % 12) : 12,
- fmt_padding[PAD_FMT_SHMS][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_SHMS][PadIndex],
+ pt, ptlim, loc);
continue;
case 'M':
pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex],
- pt, ptlim);
+ pt, ptlim, loc);
continue;
case 'm':
pt = _conv(t->tm_mon + 1,
- fmt_padding[PAD_FMT_MONTH][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_MONTH][PadIndex],
+ pt, ptlim, loc);
continue;
case 'n':
pt = _add("\n", pt, ptlim);
@@ -294,8 +300,7 @@
continue;
case 'p':
pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ?
- tptr->pm :
- tptr->am,
+ tptr->pm : tptr->am,
pt, ptlim);
continue;
case 'R':
@@ -307,7 +312,7 @@
continue;
case 'S':
pt = _conv(t->tm_sec, fmt_padding[PAD_FMT_HMS][PadIndex],
- pt, ptlim);
+ pt, ptlim, loc);
continue;
case 's':
{
@@ -319,9 +324,9 @@
tm = *t;
mkt = mktime(&tm);
if (TYPE_SIGNED(time_t))
- (void) sprintf(buf, "%ld",
+ (void) sprintf_l(buf, loc, "%ld",
(long) mkt);
- else (void) sprintf(buf, "%lu",
+ else (void) sprintf_l(buf, loc, "%lu",
(unsigned long) mkt);
pt = _add(buf, pt, ptlim);
}
@@ -335,40 +340,41 @@
case 'U':
pt = _conv((t->tm_yday + DAYSPERWEEK -
t->tm_wday) / DAYSPERWEEK,
- fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
+ pt, ptlim, loc);
continue;
case 'u':
/*
- ** From Arnold Robbins' strftime version 3.0:
- ** "ISO 8601: Weekday as a decimal number
- ** [1 (Monday) - 7]"
- ** (ado, 1993-05-24)
- */
+ * From Arnold Robbins' strftime version 3.0:
+ * "ISO 8601: Weekday as a decimal number
+ * [1 (Monday) - 7]"
+ * (ado, 1993-05-24)
+ */
pt = _conv((t->tm_wday == 0) ?
DAYSPERWEEK : t->tm_wday,
- "%d", pt, ptlim);
+ "%d", pt, ptlim, loc);
continue;
case 'V': /* ISO 8601 week number */
case 'G': /* ISO 8601 year (four digits) */
case 'g': /* ISO 8601 year (two digits) */
/*
-** From Arnold Robbins' strftime version 3.0: "the week number of the
-** year (the first Monday as the first day of week 1) as a decimal number
-** (01-53)."
-** (ado, 1993-05-24)
-**
-** From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
-** "Week 01 of a year is per definition the first week which has the
-** Thursday in this year, which is equivalent to the week which contains
-** the fourth day of January. In other words, the first week of a new year
-** is the week which has the majority of its days in the new year. Week 01
-** might also contain days from the previous year and the week before week
-** 01 of a year is the last week (52 or 53) of the previous year even if
-** it contains days from the new year. A week starts with Monday (day 1)
-** and ends with Sunday (day 7). For example, the first week of the year
-** 1997 lasts from 1996-12-30 to 1997-01-05..."
-** (ado, 1996-01-02)
-*/
+ * From Arnold Robbins' strftime version 3.0: "the week number of the
+ * year (the first Monday as the first day of week 1) as a decimal number
+ * (01-53)."
+ * (ado, 1993-05-24)
+ *
+ * From "http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html" by Markus Kuhn:
+ * "Week 01 of a year is per definition the first week which has the
+ * Thursday in this year, which is equivalent to the week which contains
+ * the fourth day of January. In other words, the first week of a new year
+ * is the week which has the majority of its days in the new year. Week 01
+ * might also contain days from the previous year and the week before week
+ * 01 of a year is the last week (52 or 53) of the previous year even if
+ * it contains days from the new year. A week starts with Monday (day 1)
+ * and ends with Sunday (day 7). For example, the first week of the year
+ * 1997 lasts from 1996-12-30 to 1997-01-05..."
+ * (ado, 1996-01-02)
+ */
{
int year;
int base;
@@ -389,15 +395,15 @@
DAYSPERLYEAR :
DAYSPERNYEAR;
/*
- ** What yday (-3 ... 3) does
- ** the ISO year begin on?
- */
+ * What yday (-3 ... 3) does
+ * the ISO year begin on?
+ */
bot = ((yday + 11 - wday) %
DAYSPERWEEK) - 3;
/*
- ** What yday does the NEXT
- ** ISO year begin on?
- */
+ * What yday does the NEXT
+ * ISO year begin on?
+ */
top = bot -
(len % DAYSPERWEEK);
if (top < -3)
@@ -427,21 +433,21 @@
#endif /* defined XPG4_1994_04_09 */
if (*format == 'V')
pt = _conv(w, fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
- pt, ptlim);
+ pt, ptlim, loc);
else if (*format == 'g') {
*warnp = IN_ALL;
pt = _yconv(year, base, 0, 1,
- pt, ptlim);
+ pt, ptlim, loc);
} else pt = _yconv(year, base, 1, 1,
- pt, ptlim);
+ pt, ptlim, loc);
}
continue;
case 'v':
/*
- ** From Arnold Robbins' strftime version 3.0:
- ** "date as dd-bbb-YYYY"
- ** (ado, 1993-05-24)
- */
+ * From Arnold Robbins' strftime version 3.0:
+ * "date as dd-bbb-YYYY"
+ * (ado, 1993-05-24)
+ */
pt = _fmt("%e-%b-%Y", t, pt, ptlim, warnp, loc);
continue;
case 'W':
@@ -449,10 +455,11 @@
(t->tm_wday ?
(t->tm_wday - 1) :
(DAYSPERWEEK - 1))) / DAYSPERWEEK,
- fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_WEEKOFYEAR][PadIndex],
+ pt, ptlim, loc);
continue;
case 'w':
- pt = _conv(t->tm_wday, "%d", pt, ptlim);
+ pt = _conv(t->tm_wday, "%d", pt, ptlim, loc);
continue;
case 'X':
pt = _fmt(tptr->X_fmt, t, pt, ptlim, warnp, loc);
@@ -471,11 +478,11 @@
case 'y':
*warnp = IN_ALL;
pt = _yconv(t->tm_year, TM_YEAR_BASE, 0, 1,
- pt, ptlim);
+ pt, ptlim, loc);
continue;
case 'Y':
pt = _yconv(t->tm_year, TM_YEAR_BASE, 1, 1,
- pt, ptlim);
+ pt, ptlim, loc);
continue;
case 'Z':
#ifdef TM_ZONE
@@ -487,10 +494,10 @@
pt = _add(tzname[t->tm_isdst != 0],
pt, ptlim);
/*
- ** C99 says that %Z must be replaced by the
- ** empty string if the time zone is not
- ** determinable.
- */
+ * C99 says that %Z must be replaced by the
+ * empty string if the time zone is not
+ * determinable.
+ */
continue;
case 'z':
{
@@ -503,24 +510,24 @@
diff = t->TM_GMTOFF;
#else /* !defined TM_GMTOFF */
/*
- ** C99 says that the UTC offset must
- ** be computed by looking only at
- ** tm_isdst. This requirement is
- ** incorrect, since it means the code
- ** must rely on magic (in this case
- ** altzone and timezone), and the
- ** magic might not have the correct
- ** offset. Doing things correctly is
- ** tricky and requires disobeying C99;
- ** see GNU C strftime for details.
- ** For now, punt and conform to the
- ** standard, even though it's incorrect.
- **
- ** C99 says that %z must be replaced by the
- ** empty string if the time zone is not
- ** determinable, so output nothing if the
- ** appropriate variables are not available.
- */
+ * C99 says that the UTC offset must
+ * be computed by looking only at
+ * tm_isdst. This requirement is
+ * incorrect, since it means the code
+ * must rely on magic (in this case
+ * altzone and timezone), and the
+ * magic might not have the correct
+ * offset. Doing things correctly is
+ * tricky and requires disobeying C99;
+ * see GNU C strftime for details.
+ * For now, punt and conform to the
+ * standard, even though it's incorrect.
+ *
+ * C99 says that %z must be replaced by the
+ * empty string if the time zone is not
+ * determinable, so output nothing if the
+ * appropriate variables are not available.
+ */
if (t->tm_isdst == 0)
#ifdef USG_COMPAT
diff = -timezone;
@@ -537,13 +544,15 @@
if (diff < 0) {
sign = "-";
diff = -diff;
- } else sign = "+";
+ } else
+ sign = "+";
pt = _add(sign, pt, ptlim);
diff /= SECSPERMIN;
diff = (diff / MINSPERHOUR) * 100 +
(diff % MINSPERHOUR);
pt = _conv(diff,
- fmt_padding[PAD_FMT_YEAR][PadIndex], pt, ptlim);
+ fmt_padding[PAD_FMT_YEAR][PadIndex],
+ pt, ptlim, loc);
}
continue;
case '+':
@@ -567,10 +576,10 @@
goto label;
case '%':
/*
- ** X311J/88-090 (4.12.3.5): if conversion char is
- ** undefined, behavior is undefined. Print out the
- ** character itself as printf(3) also does.
- */
+ * X311J/88-090 (4.12.3.5): if conversion char is
+ * undefined, behavior is undefined. Print out the
+ * character itself as printf(3) also does.
+ */
default:
break;
}
@@ -579,19 +588,20 @@
break;
*pt++ = *format;
}
- return pt;
+ return (pt);
}
static char *
-_conv(n, format, pt, ptlim)
+_conv(n, format, pt, ptlim, loc)
const int n;
const char * const format;
char * const pt;
const char * const ptlim;
+locale_t loc;
{
char buf[INT_STRLEN_MAXIMUM(int) + 1];
- (void) sprintf(buf, format, n);
+ (void) sprintf_l(buf, loc, format, n);
return _add(buf, pt, ptlim);
}
@@ -603,19 +613,19 @@
{
while (pt < ptlim && (*pt = *str++) != '\0')
++pt;
- return pt;
+ return (pt);
}
/*
-** POSIX and the C Standard are unclear or inconsistent about
-** what %C and %y do if the year is negative or exceeds 9999.
-** Use the convention that %C concatenated with %y yields the
-** same output as %Y, and that %Y contains at least 4 bytes,
-** with more only if necessary.
-*/
+ * POSIX and the C Standard are unclear or inconsistent about
+ * what %C and %y do if the year is negative or exceeds 9999.
+ * Use the convention that %C concatenated with %y yields the
+ * same output as %Y, and that %Y contains at least 4 bytes,
+ * with more only if necessary.
+ */
static char *
-_yconv(a, b, convert_top, convert_yy, pt, ptlim)
+_yconv(a, b, convert_top, convert_yy, pt, ptlim, loc)
const int a;
const int b;
const int convert_top;
@@ -622,11 +632,12 @@
const int convert_yy;
char * pt;
const char * const ptlim;
+locale_t loc;
{
register int lead;
register int trail;
-#define DIVISOR 100
+#define DIVISOR 100
trail = a % DIVISOR + b % DIVISOR;
lead = a / DIVISOR + b / DIVISOR + trail / DIVISOR;
trail %= DIVISOR;
@@ -640,9 +651,10 @@
if (convert_top) {
if (lead == 0 && trail < 0)
pt = _add("-0", pt, ptlim);
- else pt = _conv(lead, "%02d", pt, ptlim);
+ else pt = _conv(lead, "%02d", pt, ptlim, loc);
}
if (convert_yy)
- pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt, ptlim);
- return pt;
+ pt = _conv(((trail < 0) ? -trail : trail), "%02d", pt,
+ ptlim, loc);
+ return (pt);
}
Modified: trunk/lib/libc/stdtime/strptime.3
===================================================================
--- trunk/lib/libc/stdtime/strptime.3 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/strptime.3 2018-06-07 22:53:14 UTC (rev 10528)
@@ -23,9 +23,10 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
+.\" $FreeBSD: stable/10/lib/libc/stdtime/strptime.3 272758 2014-10-08 16:29:46Z pfg $
.\" $MidnightBSD$
-.\" "
-.Dd June 25, 2012
+.\"
+.Dd October 2, 2014
.Dt STRPTIME 3
.Os
.Sh NAME
@@ -80,6 +81,11 @@
are now interpreted as beginning at 1969 per POSIX requirements.
Years 69-00 are interpreted in the 20th century (1969-2000), years
01-68 in the 21st century (2001-2068).
+The
+.Fa \&%U
+and
+.Fa %W
+format specifiers accept any value within the range 00 to 53.
.Pp
If the
.Fa format
@@ -161,14 +167,6 @@
is taken as noon.
.Pp
The
-.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).
-.Pp
-The
.Fa %Z
format specifier only accepts time zone abbreviations of the local time zone,
or the value "GMT".
Property changes on: trunk/lib/libc/stdtime/strptime.3
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/lib/libc/stdtime/strptime.c
===================================================================
--- trunk/lib/libc/stdtime/strptime.c 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/strptime.c 2018-06-07 22:53:14 UTC (rev 10528)
@@ -1,25 +1,6 @@
-/*
- * Powerdog Industries kindly requests feedback from anyone modifying
- * this function:
- *
- * Date: Thu, 05 Jun 1997 23:17:17 -0400
- * From: Kevin Ruddy <kevin.ruddy at powerdog.com>
- * To: James FitzGibbon <james at nexis.net>
- * Subject: Re: Use of your strptime(3) code (fwd)
- *
- * The reason for the "no mod" clause was so that modifications would
- * come back and we could integrate them and reissue so that a wider
- * audience could use it (thereby spreading the wealth). This has
- * made it possible to get strptime to work on many operating systems.
- * I'm not sure why that's "plain unacceptable" to the FreeBSD team.
- *
- * Anyway, you can change it to "with or without modification" as
- * you see fit. Enjoy.
- *
- * Kevin Ruddy
- * Powerdog Industries, Inc.
- */
-/*
+/*-
+ * Copyright (c) 2014 Gary Mills
+ * Copyright 2011, Nexenta Systems, Inc. All rights reserved.
* Copyright (c) 1994 Powerdog Industries. All rights reserved.
*
* Copyright (c) 2011 The FreeBSD Foundation
@@ -36,12 +17,6 @@
* notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
- * 3. All advertising materials mentioning features or use of this
- * software must display the following acknowledgement:
- * This product includes software developed by Powerdog Industries.
- * 4. The name of Powerdog Industries may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
*
* THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
@@ -54,6 +29,10 @@
* 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.
+ *
+ * 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.
*/
#include <sys/cdefs.h>
@@ -76,11 +55,33 @@
#include "un-namespace.h"
#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]))
+#define FLAG_NONE (1 << 0)
+#define FLAG_YEAR (1 << 1)
+#define FLAG_MONTH (1 << 2)
+#define FLAG_YDAY (1 << 3)
+#define FLAG_MDAY (1 << 4)
+#define FLAG_WDAY (1 << 5)
+
+/*
+ * Calculate the week day of the first day of a year. Valid for
+ * the Gregorian calendar, which began Sept 14, 1752 in the UK
+ * and its colonies. Ref:
+ * http://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week
+ */
+
+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)
@@ -87,16 +88,21 @@
{
char c;
const char *ptr;
- int i,
- len;
+ int day_offset = -1, wday_offset;
+ int week_offset;
+ int i, len;
+ int flags;
int Ealternative, Oalternative;
- struct lc_time_T *tptr = __get_current_time_locale(locale);
+ const 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}
+ };
+ flags = FLAG_NONE;
+
ptr = fmt;
while (*ptr != 0) {
- if (*buf == 0)
- break;
-
c = *ptr++;
if (c != '%') {
@@ -105,7 +111,7 @@
isspace_l((unsigned char)*buf, locale))
buf++;
else if (c != *buf++)
- return 0;
+ return (NULL);
continue;
}
@@ -114,21 +120,21 @@
label:
c = *ptr++;
switch (c) {
- case 0:
case '%':
if (*buf++ != '%')
- return 0;
+ return (NULL);
break;
case '+':
buf = _strptime(buf, tptr->date_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
+ flags |= FLAG_WDAY | FLAG_MONTH | FLAG_MDAY | FLAG_YEAR;
break;
case 'C':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
/* XXX This will break for 3-digit centuries. */
len = 2;
@@ -139,21 +145,25 @@
len--;
}
if (i < 19)
- return 0;
+ return (NULL);
- tm->tm_year = i * 100 - 1900;
+ tm->tm_year = i * 100 - TM_YEAR_BASE;
+ flags |= FLAG_YEAR;
+
break;
case 'c':
buf = _strptime(buf, tptr->c_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
+ flags |= FLAG_WDAY | FLAG_MONTH | FLAG_MDAY | FLAG_YEAR;
break;
case 'D':
buf = _strptime(buf, "%m/%d/%y", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
+ flags |= FLAG_MONTH | FLAG_MDAY | FLAG_YEAR;
break;
case 'E':
@@ -170,43 +180,45 @@
case 'F':
buf = _strptime(buf, "%Y-%m-%d", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
+ flags |= FLAG_MONTH | FLAG_MDAY | FLAG_YEAR;
break;
case 'R':
buf = _strptime(buf, "%H:%M", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'r':
buf = _strptime(buf, tptr->ampm_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'T':
buf = _strptime(buf, "%H:%M:%S", tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'X':
buf = _strptime(buf, tptr->X_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
break;
case 'x':
buf = _strptime(buf, tptr->x_fmt, tm, GMTp, locale);
- if (buf == 0)
- return 0;
+ if (buf == NULL)
+ return (NULL);
+ flags |= FLAG_MONTH | FLAG_MDAY | FLAG_YEAR;
break;
case 'j':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 3;
for (i = 0; len && *buf != 0 &&
@@ -216,9 +228,11 @@
len--;
}
if (i < 1 || i > 366)
- return 0;
+ return (NULL);
tm->tm_yday = i - 1;
+ flags |= FLAG_YDAY;
+
break;
case 'M':
@@ -228,7 +242,7 @@
break;
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -240,19 +254,14 @@
if (c == 'M') {
if (i > 59)
- return 0;
+ return (NULL);
tm->tm_min = i;
} else {
if (i > 60)
- return 0;
+ return (NULL);
tm->tm_sec = i;
}
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
break;
case 'H':
@@ -268,7 +277,7 @@
* digits if used incorrectly.
*/
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -279,17 +288,12 @@
}
if (c == 'H' || c == 'k') {
if (i > 23)
- return 0;
+ return (NULL);
} else if (i > 12)
- return 0;
+ return (NULL);
tm->tm_hour = i;
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
break;
case 'p':
@@ -297,10 +301,11 @@
* XXX This is bogus if parsed before hour-related
* specifiers.
*/
+ if (tm->tm_hour > 12)
+ return (NULL);
+
len = strlen(tptr->am);
if (strncasecmp_l(buf, tptr->am, len, locale) == 0) {
- if (tm->tm_hour > 12)
- return 0;
if (tm->tm_hour == 12)
tm->tm_hour = 0;
buf += len;
@@ -309,8 +314,6 @@
len = strlen(tptr->pm);
if (strncasecmp_l(buf, tptr->pm, len, locale) == 0) {
- if (tm->tm_hour > 12)
- return 0;
if (tm->tm_hour != 12)
tm->tm_hour += 12;
buf += len;
@@ -317,7 +320,7 @@
break;
}
- return 0;
+ return (NULL);
case 'A':
case 'a':
@@ -332,10 +335,11 @@
break;
}
if (i == asizeof(tptr->weekday))
- return 0;
+ return (NULL);
+ buf += len;
tm->tm_wday = i;
- buf += len;
+ flags |= FLAG_WDAY;
break;
case 'U':
@@ -347,7 +351,7 @@
* range for now.
*/
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -357,37 +361,47 @@
len--;
}
if (i > 53)
- return 0;
+ return (NULL);
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
+ if (c == 'U')
+ day_offset = TM_SUNDAY;
+ else
+ day_offset = TM_MONDAY;
+
+
+ week_offset = i;
+
break;
+ case 'u':
case 'w':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
- i = *buf - '0';
- if (i > 6)
- return 0;
+ i = *buf++ - '0';
+ if (i < 0 || i > 7 || (c == 'u' && i < 1) ||
+ (c == 'w' && i > 6))
+ return (NULL);
- tm->tm_wday = i;
+ tm->tm_wday = i % 7;
+ flags |= FLAG_WDAY;
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
break;
- case 'd':
case 'e':
/*
- * The %e specifier is explicitly documented as not
- * being zero-padded but there is no harm in allowing
+ * 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
* such padding.
*
* XXX The %e specifier may gobble one too many
@@ -394,7 +408,7 @@
* digits if used incorrectly.
*/
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -404,15 +418,11 @@
len--;
}
if (i > 31)
- return 0;
+ return (NULL);
tm->tm_mday = i;
+ flags |= FLAG_MDAY;
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
break;
case 'B':
@@ -447,15 +457,17 @@
}
}
if (i == asizeof(tptr->month))
- return 0;
+ return (NULL);
tm->tm_mon = i;
buf += len;
+ flags |= FLAG_MONTH;
+
break;
case 'm':
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = 2;
for (i = 0; len && *buf != 0 &&
@@ -465,15 +477,11 @@
len--;
}
if (i < 1 || i > 12)
- return 0;
+ return (NULL);
tm->tm_mon = i - 1;
+ flags |= FLAG_MONTH;
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
break;
case 's':
@@ -488,12 +496,15 @@
n = strtol_l(buf, &cp, 10, locale);
if (errno == ERANGE || (long)(t = n) != n) {
errno = sverrno;
- return 0;
+ return (NULL);
}
errno = sverrno;
buf = cp;
- gmtime_r(&t, tm);
+ if (gmtime_r(&t, tm) == NULL)
+ return (NULL);
*GMTp = 1;
+ flags |= FLAG_YDAY | FLAG_WDAY | FLAG_MONTH |
+ FLAG_MDAY | FLAG_YEAR;
}
break;
@@ -504,7 +515,7 @@
break;
if (!isdigit_l((unsigned char)*buf, locale))
- return 0;
+ return (NULL);
len = (c == 'Y') ? 4 : 2;
for (i = 0; len && *buf != 0 &&
@@ -514,19 +525,15 @@
len--;
}
if (c == 'Y')
- i -= 1900;
+ i -= TM_YEAR_BASE;
if (c == 'y' && i < 69)
i += 100;
if (i < 0)
- return 0;
+ return (NULL);
tm->tm_year = i;
+ flags |= FLAG_YEAR;
- if (*buf != 0 &&
- isspace_l((unsigned char)*buf, locale))
- while (*ptr != 0 &&
- !isspace_l((unsigned char)*ptr, locale))
- ptr++;
break;
case 'Z':
@@ -542,7 +549,8 @@
strncpy(zonestr, buf, cp - buf);
zonestr[cp - buf] = '\0';
tzset();
- if (0 == strcmp(zonestr, "GMT")) {
+ if (0 == strcmp(zonestr, "GMT") ||
+ 0 == strcmp(zonestr, "UTC")) {
*GMTp = 1;
} else if (0 == strcmp(zonestr, tzname[0])) {
tm->tm_isdst = 0;
@@ -549,7 +557,7 @@
} else if (0 == strcmp(zonestr, tzname[1])) {
tm->tm_isdst = 1;
} else {
- return 0;
+ return (NULL);
}
buf += cp - buf;
}
@@ -564,7 +572,7 @@
if (*buf == '-')
sign = -1;
else
- return 0;
+ return (NULL);
}
buf++;
@@ -574,21 +582,104 @@
i *= 10;
i += *buf - '0';
buf++;
+ } else if (len == 2) {
+ i *= 100;
+ break;
} else
- return 0;
+ return (NULL);
}
+ if (i > 1400 || (sign == -1 && i > 1200) ||
+ (i % 100) >= 60)
+ return (NULL);
tm->tm_hour -= sign * (i / 100);
tm->tm_min -= sign * (i % 100);
*GMTp = 1;
}
break;
+
+ case 'n':
+ case 't':
+ while (isspace_l((unsigned char)*buf, locale))
+ buf++;
+ break;
+
+ default:
+ return (NULL);
}
}
- return (char *)buf;
+
+ if (!(flags & FLAG_YDAY) && (flags & FLAG_YEAR)) {
+ if ((flags & (FLAG_MONTH | FLAG_MDAY)) ==
+ (FLAG_MONTH | FLAG_MDAY)) {
+ tm->tm_yday = start_of_month[isleap(tm->tm_year +
+ TM_YEAR_BASE)][tm->tm_mon] + (tm->tm_mday - 1);
+ flags |= FLAG_YDAY;
+ } else if (day_offset != -1) {
+ int tmpwday, tmpyday, fwo;
+
+ fwo = first_wday_of(tm->tm_year + TM_YEAR_BASE);
+ /* No incomplete week (week 0). */
+ if (week_offset == 0 && fwo == day_offset)
+ return (NULL);
+
+ /* Set the date to the first Sunday (or Monday)
+ * of the specified week of the year.
+ */
+ tmpwday = (flags & FLAG_WDAY) ? tm->tm_wday :
+ day_offset;
+ tmpyday = (7 - fwo + day_offset) % 7 +
+ (week_offset - 1) * 7 +
+ (tmpwday - day_offset + 7) % 7;
+ /* Impossible yday for incomplete week (week 0). */
+ if (tmpyday < 0) {
+ if (flags & FLAG_WDAY)
+ return (NULL);
+ tmpyday = 0;
+ }
+ tm->tm_yday = tmpyday;
+ flags |= FLAG_YDAY;
+ }
+ }
+
+ if ((flags & (FLAG_YEAR | FLAG_YDAY)) == (FLAG_YEAR | FLAG_YDAY)) {
+ if (!(flags & FLAG_MONTH)) {
+ i = 0;
+ while (tm->tm_yday >=
+ start_of_month[isleap(tm->tm_year +
+ TM_YEAR_BASE)][i])
+ i++;
+ if (i > 12) {
+ i = 1;
+ tm->tm_yday -=
+ start_of_month[isleap(tm->tm_year +
+ TM_YEAR_BASE)][12];
+ tm->tm_year++;
+ }
+ tm->tm_mon = i - 1;
+ flags |= FLAG_MONTH;
+ }
+ if (!(flags & FLAG_MDAY)) {
+ tm->tm_mday = tm->tm_yday -
+ start_of_month[isleap(tm->tm_year + TM_YEAR_BASE)]
+ [tm->tm_mon] + 1;
+ flags |= FLAG_MDAY;
+ }
+ if (!(flags & FLAG_WDAY)) {
+ i = 0;
+ wday_offset = first_wday_of(tm->tm_year);
+ while (i++ <= tm->tm_yday) {
+ if (wday_offset++ >= 6)
+ wday_offset = 0;
+ }
+ tm->tm_wday = wday_offset;
+ flags |= FLAG_WDAY;
+ }
+ }
+
+ return ((char *)buf);
}
-
char *
strptime_l(const char * __restrict buf, const char * __restrict fmt,
struct tm * __restrict tm, locale_t loc)
@@ -601,11 +692,13 @@
ret = _strptime(buf, fmt, tm, &gmt, loc);
if (ret && gmt) {
time_t t = timegm(tm);
+
localtime_r(&t, tm);
}
return (ret);
}
+
char *
strptime(const char * __restrict buf, const char * __restrict fmt,
struct tm * __restrict tm)
Modified: trunk/lib/libc/stdtime/timelocal.c
===================================================================
--- trunk/lib/libc/stdtime/timelocal.c 2018-06-07 22:50:31 UTC (rev 10527)
+++ trunk/lib/libc/stdtime/timelocal.c 2018-06-07 22:53:14 UTC (rev 10528)
@@ -46,7 +46,7 @@
struct xlocale_time __xlocale_global_time;
-#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
+#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
static const struct lc_time_T _C_time_locale = {
{
More information about the Midnightbsd-cvs
mailing list