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.
 
 
 
 

26 lines
547 B

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