summaryrefslogtreecommitdiff
path: root/ucspi-tcp-0.88/fmt_xlong.c
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-29 15:45:38 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:45:38 -0700
commit0d2205555e68f414eec0afa8a6531626f77c4a57 (patch)
treef0e7d3e161f82180e834a6368d41b79272ab013a /ucspi-tcp-0.88/fmt_xlong.c
parent0c7195dea3482bd4c9ac9fbff318c24c502574c6 (diff)
parent01ef1d365e5776b130e8b65772a80b6adcb0ed46 (diff)
Merge branch 'master' of ephedra:usr/src/qmail into e_master
Diffstat (limited to 'ucspi-tcp-0.88/fmt_xlong.c')
-rw-r--r--ucspi-tcp-0.88/fmt_xlong.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/ucspi-tcp-0.88/fmt_xlong.c b/ucspi-tcp-0.88/fmt_xlong.c
new file mode 100644
index 0000000..332fc9a
--- /dev/null
+++ b/ucspi-tcp-0.88/fmt_xlong.c
@@ -0,0 +1,22 @@
+#include "fmt.h"
+
+char tohex(char num) {
+ if (num<10)
+ return num+'0';
+ else if (num<16)
+ return num-10+'a';
+ else
+ return -1;
+}
+
+unsigned int fmt_xlong(register char *s,register unsigned long u)
+{
+ register unsigned int len; register unsigned long q;
+ len = 1; q = u;
+ while (q > 15) { ++len; q /= 16; }
+ if (s) {
+ s += len;
+ do { *--s = tohex(u % 16); u /= 16; } while(u); /* handles u == 0 */
+ }
+ return len;
+}