Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

27 lines
608 B

  1. #include "fmt.h"
  2. size_t fmt_8longlong(char *dest,unsigned long long i) {
  3. register unsigned long len;
  4. unsigned long long tmp;
  5. /* first count the number of bytes needed */
  6. for (len=1, tmp=i; tmp>7; ++len) tmp>>=3;
  7. if (dest)
  8. for (tmp=i, dest+=len; ; ) {
  9. *--dest = (char)((tmp&7)+'0');
  10. if (!(tmp>>=3)) break;
  11. }
  12. return len;
  13. }
  14. #ifdef UNITTEST
  15. #include <assert.h>
  16. #include <string.h>
  17. int main() {
  18. char buf[100];
  19. assert(fmt_8longlong(buf,0)==1 && !memcmp(buf,"0",1));
  20. assert(fmt_8longlong(buf,0123456701234567)==15 && !memcmp(buf,"123456701234567",15));
  21. return 0;
  22. }
  23. #endif