| 1 | #include <stdlib.h> |
| 2 | #include <string.h> |
| 3 | #include <stdint.h> |
| 4 | |
| 5 | static const char digits[] = |
| 6 | 	"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; |
| 7 | |
| 8 | long a64l(const char *s) |
| 9 | { |
| 10 | 	int e; |
| 11 | 	uint32_t x = 0; |
| 12 | 	for (e=0; e<36 && *s; e+=6, s++) { |
| 13 | 		const char *d = strchr(digits, *s); |
| 14 | 		if (!d) break; |
| 15 | 		x |= (uint32_t)(d-digits)<<e; |
| 16 | 	} |
| 17 | 	return (int32_t)x; |
| 18 | } |
| 19 | |
| 20 | char *l64a(long x0) |
| 21 | { |
| 22 | 	static char s[7]; |
| 23 | 	char *p; |
| 24 | 	uint32_t x = x0; |
| 25 | 	for (p=s; x; p++, x>>=6) |
| 26 | 		*p = digits[x&63]; |
| 27 | 	*p = 0; |
| 28 | 	return s; |
| 29 | } |