* Print message specified by @format and args. * Automatically manage buffer space and transparently handle * buffer overruns. * * Returns number of bytes that should have been printed. */
| 472 | * Returns number of bytes that should have been printed. |
| 473 | */ |
| 474 | int |
| 475 | bprintf(struct buf_pr *b, const char *format, ...) |
| 476 | { |
| 477 | va_list args; |
| 478 | int i; |
| 479 | |
| 480 | va_start(args, format); |
| 481 | |
| 482 | i = vsnprintf(b->ptr, b->avail, format, args); |
| 483 | va_end(args); |
| 484 | |
| 485 | if (i < 0 || (size_t)i > b->avail) { |
| 486 | /* Overflow or print error */ |
| 487 | b->avail = 0; |
| 488 | } else { |
| 489 | b->ptr += i; |
| 490 | b->avail -= i; |
| 491 | } |
| 492 | |
| 493 | b->needed += i; |
| 494 | |
| 495 | return (i); |
| 496 | } |
| 497 | |
| 498 | /* |
| 499 | * Special values printer for tablearg-aware opcodes. |
no test coverage detected