* Convert number to string and return start of string. * Note: string does not start at beginning of buffer. */
| 19 | * Note: string does not start at beginning of buffer. |
| 20 | */ |
| 21 | static char *safe_itoa(long val, char *buf, size_t len, unsigned int radix) |
| 22 | { |
| 23 | char *bp = buf + len; |
| 24 | static const char hexdigit[] = "0123456789abcdef"; |
| 25 | |
| 26 | *--bp = '\0'; /* Null terminate the string */ |
| 27 | do { |
| 28 | /* if buffer is not big enough, then truncate */ |
| 29 | if (bp == buf) |
| 30 | return bp; |
| 31 | |
| 32 | *--bp = hexdigit[val % radix]; |
| 33 | val /= radix; |
| 34 | } while (val != 0); |
| 35 | |
| 36 | return bp; |
| 37 | } |
| 38 | |
| 39 | /* |
| 40 | * Dump the stack of the calling core |