diff options
Diffstat (limited to 'time')
-rw-r--r-- | time/strftime.c | 25 | ||||
-rw-r--r-- | time/strptime.c | 2 |
2 files changed, 24 insertions, 3 deletions
diff --git a/time/strftime.c b/time/strftime.c index 898bd6c98c..4cb6c9e260 100644 --- a/time/strftime.c +++ b/time/strftime.c @@ -175,6 +175,7 @@ localtime_r (t, tp) /* Some systems lack the `memset' function and we don't want to introduce additional dependencies. */ static const char spaces[16] = " "; +static const char zeroes[16] = "0000000000000000"; # define memset_space(P, Len) \ do { \ @@ -189,11 +190,26 @@ static const char spaces[16] = " "; } \ while (_len > 0); \ } while (0) + +# define memset_zero(P, Len) \ + do { \ + int _len = (Len); \ + \ + do \ + { \ + int _this = _len > 16 ? 16 : _len; \ + memcpy ((P), zeroes, _this); \ + (P) += _this; \ + _len -= _this; \ + } \ + while (_len > 0); \ + } while (0) #else # define memset_space(P, Len) (memset ((P), ' ', (Len)), (P) += (Len)) +# define memset_zero(P, Len) (memset ((P), '0', (Len)), (P) += (Len)) #endif -#define add(n, f) \ +#define add(n, f) \ do \ { \ int _n = (n); \ @@ -204,7 +220,12 @@ static const char spaces[16] = " "; if (p) \ { \ if (_delta > 0) \ - memset_space (p, _delta); \ + { \ + if (pad == '0') \ + memset_zero (p, _delta); \ + else \ + memset_space (p, _delta); \ + } \ f; \ p += _n; \ } \ diff --git a/time/strptime.c b/time/strptime.c index fd457af6c0..90b88a1ba3 100644 --- a/time/strptime.c +++ b/time/strptime.c @@ -377,7 +377,7 @@ strptime_internal (buf, format, tm, decided) case 'I': /* Match hour in 12-hour clock. */ get_number (1, 12); - tm->tm_hour = val - 1; + tm->tm_hour = val % 12; have_I = 1; break; case 'j': |