diff options
Diffstat (limited to 'openbsd-compat/bsd-snprintf.c')
-rw-r--r-- | openbsd-compat/bsd-snprintf.c | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c index 41d2be238..975991e7f 100644 --- a/openbsd-compat/bsd-snprintf.c +++ b/openbsd-compat/bsd-snprintf.c | |||
@@ -160,6 +160,8 @@ | |||
160 | #define DP_C_LONG 2 | 160 | #define DP_C_LONG 2 |
161 | #define DP_C_LDOUBLE 3 | 161 | #define DP_C_LDOUBLE 3 |
162 | #define DP_C_LLONG 4 | 162 | #define DP_C_LLONG 4 |
163 | #define DP_C_SIZE 5 | ||
164 | #define DP_C_INTMAX 6 | ||
163 | 165 | ||
164 | #define char_to_int(p) ((p)- '0') | 166 | #define char_to_int(p) ((p)- '0') |
165 | #ifndef MAX | 167 | #ifndef MAX |
@@ -182,7 +184,7 @@ static int dopr(char *buffer, size_t maxlen, const char *format, | |||
182 | static int fmtstr(char *buffer, size_t *currlen, size_t maxlen, | 184 | static int fmtstr(char *buffer, size_t *currlen, size_t maxlen, |
183 | char *value, int flags, int min, int max); | 185 | char *value, int flags, int min, int max); |
184 | static int fmtint(char *buffer, size_t *currlen, size_t maxlen, | 186 | static int fmtint(char *buffer, size_t *currlen, size_t maxlen, |
185 | LLONG value, int base, int min, int max, int flags); | 187 | intmax_t value, int base, int min, int max, int flags); |
186 | static int fmtfp(char *buffer, size_t *currlen, size_t maxlen, | 188 | static int fmtfp(char *buffer, size_t *currlen, size_t maxlen, |
187 | LDOUBLE fvalue, int min, int max, int flags); | 189 | LDOUBLE fvalue, int min, int max, int flags); |
188 | 190 | ||
@@ -190,7 +192,7 @@ static int | |||
190 | dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | 192 | dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) |
191 | { | 193 | { |
192 | char ch; | 194 | char ch; |
193 | LLONG value; | 195 | intmax_t value; |
194 | LDOUBLE fvalue; | 196 | LDOUBLE fvalue; |
195 | char *strvalue; | 197 | char *strvalue; |
196 | int min; | 198 | int min; |
@@ -287,6 +289,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
287 | cflags = DP_C_SHORT; | 289 | cflags = DP_C_SHORT; |
288 | ch = *format++; | 290 | ch = *format++; |
289 | break; | 291 | break; |
292 | case 'j': | ||
293 | cflags = DP_C_INTMAX; | ||
294 | ch = *format++; | ||
295 | break; | ||
290 | case 'l': | 296 | case 'l': |
291 | cflags = DP_C_LONG; | 297 | cflags = DP_C_LONG; |
292 | ch = *format++; | 298 | ch = *format++; |
@@ -299,6 +305,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
299 | cflags = DP_C_LDOUBLE; | 305 | cflags = DP_C_LDOUBLE; |
300 | ch = *format++; | 306 | ch = *format++; |
301 | break; | 307 | break; |
308 | case 'z': | ||
309 | cflags = DP_C_SIZE; | ||
310 | ch = *format++; | ||
311 | break; | ||
302 | default: | 312 | default: |
303 | break; | 313 | break; |
304 | } | 314 | } |
@@ -314,6 +324,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
314 | value = va_arg (args, long int); | 324 | value = va_arg (args, long int); |
315 | else if (cflags == DP_C_LLONG) | 325 | else if (cflags == DP_C_LLONG) |
316 | value = va_arg (args, LLONG); | 326 | value = va_arg (args, LLONG); |
327 | else if (cflags == DP_C_SIZE) | ||
328 | value = va_arg (args, ssize_t); | ||
329 | else if (cflags == DP_C_INTMAX) | ||
330 | value = va_arg (args, intmax_t); | ||
317 | else | 331 | else |
318 | value = va_arg (args, int); | 332 | value = va_arg (args, int); |
319 | if (fmtint(buffer, &currlen, maxlen, | 333 | if (fmtint(buffer, &currlen, maxlen, |
@@ -328,6 +342,12 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
328 | value = (long)va_arg (args, unsigned long int); | 342 | value = (long)va_arg (args, unsigned long int); |
329 | else if (cflags == DP_C_LLONG) | 343 | else if (cflags == DP_C_LLONG) |
330 | value = (long)va_arg (args, unsigned LLONG); | 344 | value = (long)va_arg (args, unsigned LLONG); |
345 | else if (cflags == DP_C_SIZE) | ||
346 | value = va_arg (args, size_t); | ||
347 | #ifdef notyet | ||
348 | else if (cflags == DP_C_INTMAX) | ||
349 | value = va_arg (args, uintmax_t); | ||
350 | #endif | ||
331 | else | 351 | else |
332 | value = (long)va_arg (args, unsigned int); | 352 | value = (long)va_arg (args, unsigned int); |
333 | if (fmtint(buffer, &currlen, maxlen, value, | 353 | if (fmtint(buffer, &currlen, maxlen, value, |
@@ -342,6 +362,12 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
342 | value = (long)va_arg (args, unsigned long int); | 362 | value = (long)va_arg (args, unsigned long int); |
343 | else if (cflags == DP_C_LLONG) | 363 | else if (cflags == DP_C_LLONG) |
344 | value = (LLONG)va_arg (args, unsigned LLONG); | 364 | value = (LLONG)va_arg (args, unsigned LLONG); |
365 | else if (cflags == DP_C_SIZE) | ||
366 | value = va_arg (args, size_t); | ||
367 | #ifdef notyet | ||
368 | else if (cflags == DP_C_INTMAX) | ||
369 | value = va_arg (args, uintmax_t); | ||
370 | #endif | ||
345 | else | 371 | else |
346 | value = (long)va_arg (args, unsigned int); | 372 | value = (long)va_arg (args, unsigned int); |
347 | if (fmtint(buffer, &currlen, maxlen, value, | 373 | if (fmtint(buffer, &currlen, maxlen, value, |
@@ -358,6 +384,12 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
358 | value = (long)va_arg (args, unsigned long int); | 384 | value = (long)va_arg (args, unsigned long int); |
359 | else if (cflags == DP_C_LLONG) | 385 | else if (cflags == DP_C_LLONG) |
360 | value = (LLONG)va_arg (args, unsigned LLONG); | 386 | value = (LLONG)va_arg (args, unsigned LLONG); |
387 | else if (cflags == DP_C_SIZE) | ||
388 | value = va_arg (args, size_t); | ||
389 | #ifdef notyet | ||
390 | else if (cflags == DP_C_INTMAX) | ||
391 | value = va_arg (args, uintmax_t); | ||
392 | #endif | ||
361 | else | 393 | else |
362 | value = (long)va_arg (args, unsigned int); | 394 | value = (long)va_arg (args, unsigned int); |
363 | if (fmtint(buffer, &currlen, maxlen, value, | 395 | if (fmtint(buffer, &currlen, maxlen, value, |
@@ -416,6 +448,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
416 | (long) strvalue, 16, min, max, flags) == -1) | 448 | (long) strvalue, 16, min, max, flags) == -1) |
417 | return -1; | 449 | return -1; |
418 | break; | 450 | break; |
451 | #if we_dont_want_this_in_openssh | ||
419 | case 'n': | 452 | case 'n': |
420 | if (cflags == DP_C_SHORT) { | 453 | if (cflags == DP_C_SHORT) { |
421 | short int *num; | 454 | short int *num; |
@@ -429,12 +462,21 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) | |||
429 | LLONG *num; | 462 | LLONG *num; |
430 | num = va_arg (args, LLONG *); | 463 | num = va_arg (args, LLONG *); |
431 | *num = (LLONG)currlen; | 464 | *num = (LLONG)currlen; |
465 | } else if (cflags == DP_C_SIZE) { | ||
466 | ssize_t *num; | ||
467 | num = va_arg (args, ssize_t *); | ||
468 | *num = (ssize_t)currlen; | ||
469 | } else if (cflags == DP_C_INTMAX) { | ||
470 | intmax_t *num; | ||
471 | num = va_arg (args, intmax_t *); | ||
472 | *num = (intmax_t)currlen; | ||
432 | } else { | 473 | } else { |
433 | int *num; | 474 | int *num; |
434 | num = va_arg (args, int *); | 475 | num = va_arg (args, int *); |
435 | *num = currlen; | 476 | *num = currlen; |
436 | } | 477 | } |
437 | break; | 478 | break; |
479 | #endif | ||
438 | case '%': | 480 | case '%': |
439 | DOPR_OUTCH(buffer, currlen, maxlen, ch); | 481 | DOPR_OUTCH(buffer, currlen, maxlen, ch); |
440 | break; | 482 | break; |