print into the buffer, expanding if needed */
| 66 | print into the buffer, expanding if needed |
| 67 | */ |
| 68 | void ExpandingString::printf(const char *format, ...) |
| 69 | { |
| 70 | if (allocation_failed) { |
| 71 | return; |
| 72 | } |
| 73 | if (buflen == used && !expand(0)) { |
| 74 | return; |
| 75 | } |
| 76 | int n; |
| 77 | |
| 78 | /* |
| 79 | print into the buffer, expanding the buffer if needed |
| 80 | */ |
| 81 | while (true) { |
| 82 | va_list arg; |
| 83 | va_start(arg, format); |
| 84 | n = hal.util->vsnprintf(&buf[used], buflen-used, format, arg); |
| 85 | va_end(arg); |
| 86 | if (n < 0) { |
| 87 | return; |
| 88 | } |
| 89 | if (uint32_t(n) < buflen - used) { |
| 90 | break; |
| 91 | } |
| 92 | if (!expand(n+1)) { |
| 93 | return; |
| 94 | } |
| 95 | } |
| 96 | used += n; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | print into the buffer, expanding if needed |