aboutsummaryrefslogtreecommitdiff
path: root/src/String/Inline/Unsigned.h
blob: ff57e846b4f3fbb96e7bf1f63c9f80e64c3e5ee9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;