* Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse * order; return an optional length and a pointer to the last character * written in the buffer (i.e., the first character of the string). * The buffer pointed to by `nbuf' must have length >= MAXNBUF. */
| 118 | * The buffer pointed to by `nbuf' must have length >= MAXNBUF. |
| 119 | */ |
| 120 | static char * |
| 121 | ksprintn(char *nbuf, uintmax_t num, int base, int *lenp, int upper) |
| 122 | { |
| 123 | char *p, c; |
| 124 | |
| 125 | p = nbuf; |
| 126 | *p = '\0'; |
| 127 | do { |
| 128 | c = hex2ascii(num % base); |
| 129 | *++p = upper ? toupper(c) : c; |
| 130 | } while (num /= base); |
| 131 | if (lenp) |
| 132 | *lenp = p - nbuf; |
| 133 | return (p); |
| 134 | } |
| 135 | |
| 136 | static void |
| 137 | putbuf(int c, struct putchar_arg *ap) |