diff options
Diffstat (limited to 'src/String/Inline/Unsigned.h')
| -rw-r--r-- | src/String/Inline/Unsigned.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/String/Inline/Unsigned.h b/src/String/Inline/Unsigned.h new file mode 100644 index 0000000..ff57e84 --- /dev/null +++ b/src/String/Inline/Unsigned.h @@ -0,0 +1,23 @@ +char tmp[sizeof(value) * CHAR_BIT + 1]; +char *current, *end; +end = tmp + sizeof(tmp); +current = end; + +/* Fill buffer from the end */ +*(--current) = 0; +while (value) +{ + *(--current) = digits[value % base]; + value /= base; +} + +/* Check that string have space for the result */ +if (size < (size_t)(end - current)) + return BH_ERROR; + +/* Copy data */ +memcpy(string, current, end - current); +if (actual) + *actual = end - current; + +return BH_OK; |
