[RFA] One strftime fix, two strftime additions of GNU extensions

Christopher Faylor cgf@redhat.com
Wed Jan 15 05:45:00 GMT 2003


The patch below adds missing '%h' functionality to strftime.  It also
adds the GNU '%l' and '%k' options which provides the time of day in a
left space filled format.

Ok to apply?

cgf

2003-01-14  Christopher Faylor  <cgf@redhat.com>

	* libc/time/strftime.c (strftime): Add '%h' and '%l, %k' GNU
	extensions.

Index: libc/time/strftime.c
===================================================================
RCS file: /cvs/uberbaum/newlib/libc/time/strftime.c,v
retrieving revision 1.4
diff -u -p -r1.4 strftime.c
--- libc/time/strftime.c	21 Jun 2002 20:04:40 -0000	1.4
+++ libc/time/strftime.c	15 Jan 2003 05:03:43 -0000
@@ -209,6 +209,7 @@ _DEFUN (strftime, (s, maxsize, format, t
 	    }
 	  break;
 	case 'b':
+	case 'h':
 	  for (i = 0; i < 3; i++)
 	    {
 	      if (count < maxsize - 1)
@@ -271,9 +272,10 @@ _DEFUN (strftime, (s, maxsize, format, t
 	    return 0;
 	  break;
 	case 'H':
+	case 'k':
 	  if (count < maxsize - 2)
 	    {
-	      sprintf (&s[count], "%2.2d",
+	      sprintf (&s[count], *format == 'k' ? "%2d" : "%2.2d",
 		       tim_p->tm_hour);
 	      count += 2;
 	    }
@@ -281,6 +283,7 @@ _DEFUN (strftime, (s, maxsize, format, t
 	    return 0;
 	  break;
 	case 'I':
+	case 'l':
 	  if (count < maxsize - 2)
 	    {
 	      if (tim_p->tm_hour == 0 ||
@@ -291,7 +294,7 @@ _DEFUN (strftime, (s, maxsize, format, t
 		}
 	      else
 		{
-		  sprintf (&s[count], "%.2d",
+		  sprintf (&s[count], (*format == 'I') ? "%.2d" : "%2d",
 			   tim_p->tm_hour % 12);
 		  count += 2;
 		}



More information about the Newlib mailing list