libowfat/fmt/fmt_xlong.c

19 lines
417 B
C
Raw Normal View History

2001-02-02 17:54:47 +00:00
#include "fmt.h"
2001-11-24 20:11:41 +00:00
#include "haveinline.h"
2001-02-02 17:54:47 +00:00
static inline char tohex(char c) {
2001-04-23 13:08:25 +00:00
return c>=10?c-10+'a':c+'0';
2001-02-02 17:54:47 +00:00
}
unsigned int fmt_xlong(char *dest,unsigned long i) {
register unsigned long len,tmp;
/* first count the number of bytes needed */
for (len=1, tmp=i; tmp>15; ++len) tmp>>=4;
if (dest)
2001-04-23 13:41:17 +00:00
for (tmp=i, dest+=len; ; ) {
2001-02-02 17:54:47 +00:00
*--dest = tohex(tmp&15);
2001-04-23 13:41:17 +00:00
if (!(tmp>>=4)) break;
}
2001-02-02 17:54:47 +00:00
return len;
}