Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Nov 2018 23:37:13 +0000 (UTC)
From:      Yuri Pankov <yuripv@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340106 - in head: contrib/netbsd-tests/lib/libc/time lib/libc/stdtime
Message-ID:  <201811032337.wA3NbDso084080@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: yuripv
Date: Sat Nov  3 23:37:13 2018
New Revision: 340106
URL: https://svnweb.freebsd.org/changeset/base/340106

Log:
  strptime: make %k and %l specifiers match their description in
  strftime(3), and allow them to process space-padded input.
  
  PR:		230720
  Submitted by:	rlittle@inetco.com (original version)
  Approved by:	kib (mentor, implicit)
  Differential Revision:	https://reviews.freebsd.org/D17761

Modified:
  head/contrib/netbsd-tests/lib/libc/time/t_strptime.c
  head/lib/libc/stdtime/strptime.c

Modified: head/contrib/netbsd-tests/lib/libc/time/t_strptime.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/time/t_strptime.c	Sat Nov  3 22:12:21 2018	(r340105)
+++ head/contrib/netbsd-tests/lib/libc/time/t_strptime.c	Sat Nov  3 23:37:13 2018	(r340106)
@@ -331,8 +331,19 @@ ATF_TC_BODY(hour, tc)
 
 	h_fail("00", "%I");
 	h_fail("13", "%I");
+
 #ifdef __FreeBSD__
-	h_fail("00", "%l");
+	h_pass("0", "%k", 1, -1, -1, 0, -1, -1, -1, -1, -1);
+	h_pass("04", "%k", 2, -1, -1, 4, -1, -1, -1, -1, -1);
+	h_pass(" 8", "%k", 2, -1, -1, 8, -1, -1, -1, -1, -1);
+	h_pass("23", "%k", 2, -1, -1, 23, -1, -1, -1, -1, -1);
+	h_fail("24", "%k");
+
+	h_fail("0", "%l");
+	h_pass("1", "%l", 1, -1, -1, 1, -1, -1, -1, -1, -1);
+	h_pass("05", "%l", 2, -1, -1, 5, -1, -1, -1, -1, -1);
+	h_pass(" 9", "%l", 2, -1, -1, 9, -1, -1, -1, -1, -1);
+	h_pass("12", "%l", 2, -1, -1, 12, -1, -1, -1, -1, -1);
 	h_fail("13", "%l");
 #endif
 

Modified: head/lib/libc/stdtime/strptime.c
==============================================================================
--- head/lib/libc/stdtime/strptime.c	Sat Nov  3 22:12:21 2018	(r340105)
+++ head/lib/libc/stdtime/strptime.c	Sat Nov  3 23:37:13 2018	(r340106)
@@ -272,17 +272,24 @@ label:
 		case 'k':
 		case 'l':
 			/*
-			 * Of these, %l is the only specifier explicitly
-			 * documented as not being zero-padded.  However,
-			 * there is no harm in allowing zero-padding.
+			 * %k and %l specifiers are documented as being
+			 * blank-padded.  However, there is no harm in
+			 * allowing zero-padding.
 			 *
-			 * XXX The %l specifier may gobble one too many
+			 * XXX %k and %l specifiers may gobble one too many
 			 * digits if used incorrectly.
 			 */
+
+			len = 2;
+			if ((c == 'k' || c == 'l') &&
+			    isblank_l((unsigned char)*buf, locale)) {
+				buf++;
+				len = 1;
+			}
+
 			if (!isdigit_l((unsigned char)*buf, locale))
 				return (NULL);
 
-			len = 2;
 			for (i = 0; len && *buf != 0 &&
 			     isdigit_l((unsigned char)*buf, locale); buf++) {
 				i *= 10;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811032337.wA3NbDso084080>