a64l: some of the crap in a libc is amazing
authorAlan Cox <alan@linux.intel.com>
Mon, 20 Jun 2016 18:58:17 +0000 (19:58 +0100)
committerAlan Cox <alan@linux.intel.com>
Mon, 20 Jun 2016 18:58:17 +0000 (19:58 +0100)
Library/libs/a64l.c [new file with mode: 0644]
Library/libs/l64a.c [new file with mode: 0644]

diff --git a/Library/libs/a64l.c b/Library/libs/a64l.c
new file mode 100644 (file)
index 0000000..a75c015
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+long a64l(const char *s)
+{
+  uint32_t n = 0;
+  const char *se = s + 6;
+  while(*s && s < se) {
+    n <<= 6;
+    if (*s == '.')
+      n++;
+    if (*s >= '0' && *s <= '9')
+      n += *s - '0' + 2;
+    else if (*s >= 'A' && *s <= 'Z')
+      n += *s - 'A' + 12;
+    else
+      n += *s - 'a' + 38;
+    s++;
+  }
+  return n;
+}
diff --git a/Library/libs/l64a.c b/Library/libs/l64a.c
new file mode 100644 (file)
index 0000000..d7f7b3b
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+static char buf[7];
+
+static char str[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+
+char *l64a(long l)
+{
+  uint32_t n = l;
+  char *p = buf;
+
+  while(n && p < buf + 6) {
+    *p++ = str[n & 63];
+    n >>= 6;
+  }
+  *p = 0;
+  return buf;
+}
+
+    
\ No newline at end of file