You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
547 B
C

24 years ago
#include "fmt.h"
size_t fmt_8long(char *dest,unsigned long i) {
24 years ago
register unsigned long len,tmp;
/* first count the number of bytes needed */
for (len=1, tmp=i; tmp>7; ++len) tmp>>=3;
24 years ago
if (dest)
24 years ago
for (tmp=i, dest+=len; ; ) {
*--dest = (char)((tmp&7)+'0');
24 years ago
if (!(tmp>>=3)) break;
}
24 years ago
return len;
}
#ifdef UNITTEST
#include <assert.h>
#include <string.h>
int main() {
char buf[100];
assert(fmt_8long(buf,012345)==5 && !memcmp(buf,"12345",5));
assert(fmt_8long(buf,0)==1 && !memcmp(buf,"0",1));
return 0;
}
#endif