summaryrefslogtreecommitdiff
path: root/src/libstddjb/uint64_fmt_generic.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstddjb/uint64_fmt_generic.c')
-rw-r--r--src/libstddjb/uint64_fmt_generic.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libstddjb/uint64_fmt_generic.c b/src/libstddjb/uint64_fmt_generic.c
new file mode 100644
index 0000000..54375a3
--- /dev/null
+++ b/src/libstddjb/uint64_fmt_generic.c
@@ -0,0 +1,17 @@
+/* ISC license. */
+
+#include <skalibs/uint64.h>
+#include <skalibs/fmtscan.h>
+
+size_t uint64_fmt_generic (char *s, uint64_t x, uint8_t base)
+{
+ size_t len = 1 ;
+ uint64_t q = x ;
+ while (q >= base) { len++ ; q /= base ; }
+ if (s)
+ {
+ s += len ;
+ do { *--s = fmtscan_asc(x % base) ; x /= base ; } while (x) ;
+ }
+ return len ;
+}