summaryrefslogtreecommitdiff
path: root/src/libstddjb/uint64_fmt_generic.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-07-11 17:46:58 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-07-11 17:46:58 +0000
commit7e1e6cf1584c5f1c0d6c892d013ed522fb8a8bc1 (patch)
tree0518ba66d0f3f79776ed82cd87b7128dd329f6da /src/libstddjb/uint64_fmt_generic.c
parent9ec6602c9d3c1a8801d996aa3a56c779ce1c5f70 (diff)
downloadskalibs-7e1e6cf1584c5f1c0d6c892d013ed522fb8a8bc1.tar.xz
Better with the new files added >.>
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 ;
+}