diff options
Diffstat (limited to 'src/strftime.c')
| -rw-r--r-- | src/strftime.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/strftime.c b/src/strftime.c index c0cc077b072..abd039f5b24 100644 --- a/src/strftime.c +++ b/src/strftime.c | |||
| @@ -177,6 +177,7 @@ localtime_r (t, tp) | |||
| 177 | /* Some systems lack the `memset' function and we don't want to | 177 | /* Some systems lack the `memset' function and we don't want to |
| 178 | introduce additional dependencies. */ | 178 | introduce additional dependencies. */ |
| 179 | static const char spaces[16] = " "; | 179 | static const char spaces[16] = " "; |
| 180 | static const char zeroes[16] = "0000000000000000"; | ||
| 180 | 181 | ||
| 181 | # define memset_space(P, Len) \ | 182 | # define memset_space(P, Len) \ |
| 182 | do { \ | 183 | do { \ |
| @@ -191,11 +192,26 @@ static const char spaces[16] = " "; | |||
| 191 | } \ | 192 | } \ |
| 192 | while (_len > 0); \ | 193 | while (_len > 0); \ |
| 193 | } while (0) | 194 | } while (0) |
| 195 | |||
| 196 | # define memset_zero(P, Len) \ | ||
| 197 | do { \ | ||
| 198 | int _len = (Len); \ | ||
| 199 | \ | ||
| 200 | do \ | ||
| 201 | { \ | ||
| 202 | int _this = _len > 16 ? 16 : _len; \ | ||
| 203 | memcpy ((P), zeroes, _this); \ | ||
| 204 | (P) += _this; \ | ||
| 205 | _len -= _this; \ | ||
| 206 | } \ | ||
| 207 | while (_len > 0); \ | ||
| 208 | } while (0) | ||
| 194 | #else | 209 | #else |
| 195 | # define memset_space(P, Len) (memset ((P), ' ', (Len)), (P) += (Len)) | 210 | # define memset_space(P, Len) (memset ((P), ' ', (Len)), (P) += (Len)) |
| 211 | # define memset_zero(P, Len) (memset ((P), '0', (Len)), (P) += (Len)) | ||
| 196 | #endif | 212 | #endif |
| 197 | 213 | ||
| 198 | #define add(n, f) \ | 214 | #define add(n, f) \ |
| 199 | do \ | 215 | do \ |
| 200 | { \ | 216 | { \ |
| 201 | int _n = (n); \ | 217 | int _n = (n); \ |
| @@ -206,7 +222,12 @@ static const char spaces[16] = " "; | |||
| 206 | if (p) \ | 222 | if (p) \ |
| 207 | { \ | 223 | { \ |
| 208 | if (_delta > 0) \ | 224 | if (_delta > 0) \ |
| 209 | memset_space (p, _delta); \ | 225 | { \ |
| 226 | if (pad == '0') \ | ||
| 227 | memset_zero (p, _delta); \ | ||
| 228 | else \ | ||
| 229 | memset_space (p, _delta); \ | ||
| 230 | } \ | ||
| 210 | f; \ | 231 | f; \ |
| 211 | p += _n; \ | 232 | p += _n; \ |
| 212 | } \ | 233 | } \ |