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.
 
 
 
 

23 lines
487 B

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