aboutsummaryrefslogtreecommitdiff
path: root/src/String/ToIntU.inl
diff options
context:
space:
mode:
Diffstat (limited to 'src/String/ToIntU.inl')
-rw-r--r--src/String/ToIntU.inl23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/String/ToIntU.inl b/src/String/ToIntU.inl
new file mode 100644
index 0000000..ff57e84
--- /dev/null
+++ b/src/String/ToIntU.inl
@@ -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;