2005-01-20 Jeff Johnston <jjohnstn@redhat.com>
* libc/time/strftime.c (strftime): Change %r and %x to be compliant
        to POSIX standard for "C" locale.  Allow %E and %O modifiers
        to be ignored as long as they precede valid specifiers according
        to POSIX.
			
			
This commit is contained in:
		| @@ -1,3 +1,10 @@ | |||||||
|  | 2005-01-20  Jeff Johnston  <jjohnstn@redhat.com> | ||||||
|  |  | ||||||
|  | 	* libc/time/strftime.c (strftime): Change %r and %x to be compliant | ||||||
|  | 	to POSIX standard for "C" locale.  Allow %E and %O modifiers | ||||||
|  | 	to be ignored as long as they precede valid specifiers according | ||||||
|  | 	to POSIX. | ||||||
|  |  | ||||||
| 2005-01-19  Shaun Jackman  <sjackman@gmail.com> | 2005-01-19  Shaun Jackman  <sjackman@gmail.com> | ||||||
|  |  | ||||||
| 	* libc/stdlib/setenv_r.c (_setenv_r): Call tzset() if the TZ | 	* libc/stdlib/setenv_r.c (_setenv_r): Call tzset() if the TZ | ||||||
|   | |||||||
| @@ -86,6 +86,9 @@ The minute, formatted with two digits. | |||||||
| o %p | o %p | ||||||
| Either `<<AM>>' or `<<PM>>' as appropriate. | Either `<<AM>>' or `<<PM>>' as appropriate. | ||||||
|  |  | ||||||
|  | o %r | ||||||
|  | Equivalent to "%I:%M:%S %p". | ||||||
|  |  | ||||||
| o %S | o %S | ||||||
| The second, formatted with two digits. | The second, formatted with two digits. | ||||||
|  |  | ||||||
| @@ -103,13 +106,11 @@ as beginning with the first Monday in a year. | |||||||
|  |  | ||||||
| o | o | ||||||
| o %x | o %x | ||||||
| A string representing the complete date, in a format like | A string representing the complete date, equivalent to "%m/%d/%y". | ||||||
| . Mon Apr 01 1992 |  | ||||||
|  |  | ||||||
| o %X | o %X | ||||||
| A string representing the full time of day (hours, minutes, and | A string representing the full time of day (hours, minutes, and | ||||||
| seconds), in a format like | seconds), equivalent to "%T". | ||||||
| . 13:13:13 |  | ||||||
|  |  | ||||||
| o %y | o %y | ||||||
| The last two digits of the year. | The last two digits of the year. | ||||||
| @@ -145,6 +146,7 @@ ANSI C requires <<strftime>>, but does not specify the contents of | |||||||
| #include <stddef.h> | #include <stddef.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <time.h> | #include <time.h> | ||||||
|  | #include <string.h> | ||||||
| #include "local.h" | #include "local.h" | ||||||
|  |  | ||||||
| static _CONST int dname_len[7] = | static _CONST int dname_len[7] = | ||||||
| @@ -186,6 +188,9 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), | |||||||
| 	break; | 	break; | ||||||
|  |  | ||||||
|       format++; |       format++; | ||||||
|  |  | ||||||
|  | check_format: | ||||||
|  |  | ||||||
|       switch (*format) |       switch (*format) | ||||||
| 	{ | 	{ | ||||||
| 	case 'a': | 	case 'a': | ||||||
| @@ -261,6 +266,22 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), | |||||||
| 	  else | 	  else | ||||||
| 	    return 0; | 	    return 0; | ||||||
| 	  break; | 	  break; | ||||||
|  | 	case 'E': | ||||||
|  | 	  ++format; | ||||||
|  | 	  switch (*format) | ||||||
|  |             { | ||||||
|  |               case 'c': | ||||||
|  |               case 'C': | ||||||
|  |               case 'x': | ||||||
|  |               case 'X': | ||||||
|  |               case 'y': | ||||||
|  |               case 'Y': | ||||||
|  | 	        /* Ignore.  */ | ||||||
|  | 	        goto check_format; | ||||||
|  | 	      default: | ||||||
|  | 		--format; | ||||||
|  |             } | ||||||
|  |           break; | ||||||
| 	case 'e': | 	case 'e': | ||||||
| 	  if (count < maxsize - 2) | 	  if (count < maxsize - 2) | ||||||
| 	    { | 	    { | ||||||
| @@ -332,6 +353,29 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), | |||||||
| 	  else | 	  else | ||||||
| 	    return 0; | 	    return 0; | ||||||
| 	  break; | 	  break; | ||||||
|  | 	case 'O': | ||||||
|  | 	  ++format; | ||||||
|  | 	  switch (*format) | ||||||
|  |             { | ||||||
|  |               case 'd': | ||||||
|  |               case 'e': | ||||||
|  |               case 'H': | ||||||
|  |               case 'I': | ||||||
|  |               case 'm': | ||||||
|  |               case 'M': | ||||||
|  |               case 'S': | ||||||
|  |               case 'u': | ||||||
|  |               case 'U': | ||||||
|  |               case 'V': | ||||||
|  |               case 'w': | ||||||
|  |               case 'W': | ||||||
|  |               case 'y': | ||||||
|  | 	        /* Ignore.  */ | ||||||
|  | 	        goto check_format; | ||||||
|  | 	      default: | ||||||
|  | 		--format; | ||||||
|  |             } | ||||||
|  |           break; | ||||||
| 	case 'p': | 	case 'p': | ||||||
| 	  if (count < maxsize - 2) | 	  if (count < maxsize - 2) | ||||||
| 	    { | 	    { | ||||||
| @@ -345,6 +389,39 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), | |||||||
| 	  else | 	  else | ||||||
| 	    return 0; | 	    return 0; | ||||||
| 	  break; | 	  break; | ||||||
|  | 	case 'r': | ||||||
|  | 	  if (count < maxsize - 11) | ||||||
|  | 	    { | ||||||
|  | 	      if (tim_p->tm_hour == 0 || | ||||||
|  | 		  tim_p->tm_hour == 12) | ||||||
|  | 		{ | ||||||
|  | 		  s[count++] = '1'; | ||||||
|  | 		  s[count++] = '2'; | ||||||
|  | 		} | ||||||
|  | 	      else | ||||||
|  | 		{ | ||||||
|  | 		  sprintf (&s[count], "%.2d", tim_p->tm_hour % 12); | ||||||
|  | 		  count += 2; | ||||||
|  | 		} | ||||||
|  | 	      s[count++] = ':'; | ||||||
|  | 	      sprintf (&s[count], "%2.2d", | ||||||
|  | 		       tim_p->tm_min); | ||||||
|  | 	      count += 2; | ||||||
|  | 	      s[count++] = ':'; | ||||||
|  | 	      sprintf (&s[count], "%2.2d", | ||||||
|  | 		       tim_p->tm_sec); | ||||||
|  | 	      count += 2; | ||||||
|  | 	      s[count++] = ' '; | ||||||
|  | 	      if (tim_p->tm_hour < 12) | ||||||
|  | 		s[count++] = 'A'; | ||||||
|  | 	      else | ||||||
|  | 		s[count++] = 'P'; | ||||||
|  |  | ||||||
|  | 	      s[count++] = 'M'; | ||||||
|  | 	    } | ||||||
|  | 	  else | ||||||
|  | 	    return 0; | ||||||
|  | 	  break; | ||||||
| 	case 'S': | 	case 'S': | ||||||
| 	  if (count < maxsize - 2) | 	  if (count < maxsize - 2) | ||||||
| 	    { | 	    { | ||||||
| @@ -389,20 +466,22 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), | |||||||
| 	    return 0; | 	    return 0; | ||||||
| 	  break; | 	  break; | ||||||
| 	case 'x': | 	case 'x': | ||||||
| 	  if (count < maxsize - 15) | 	  if (count < maxsize - 8) | ||||||
| 	    { | 	    { | ||||||
| 	      for (i = 0; i < 3; i++) | 	      sprintf (&s[count], "%.2d", | ||||||
| 		s[count++] = | 		       tim_p->tm_mon + 1); | ||||||
| 		  dname[tim_p->tm_wday][i]; | 	      count += 2; | ||||||
| 	      s[count++] = ' '; | 	      s[count++] = '/'; | ||||||
| 	      for (i = 0; i < 3; i++) | 	      sprintf (&s[count], "%.2d", | ||||||
| 		s[count++] = | 		       tim_p->tm_mday); | ||||||
| 		  mname[tim_p->tm_mon][i]; | 	      count += 2; | ||||||
|  | 	      s[count++] = '/'; | ||||||
| 	      sprintf (&s[count], | 	      /* The year could be greater than 100, so we need the value | ||||||
| 		       " %.2d %.4d", tim_p->tm_mday, | 		 modulo 100.  The year could be negative, so we need to | ||||||
| 		       1900 + tim_p->tm_year); | 		 correct for a possible negative remainder.  */ | ||||||
| 	      count += 8; | 	      sprintf (&s[count], "%2.2d", | ||||||
|  | 		       (tim_p->tm_year % 100 + 100) % 100); | ||||||
|  | 	      count += 2; | ||||||
| 	    } | 	    } | ||||||
| 	  else | 	  else | ||||||
| 	    return 0; | 	    return 0; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user