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.
 
 
 
 

29 lines
576 B

  1. #include "fmt.h"
  2. size_t fmt_human(char* dest,unsigned long long l) {
  3. char unit;
  4. size_t i;
  5. if (l<1000) return fmt_ulong(dest,l);
  6. if (l>1000000000000ull) {
  7. /* dang! overflow! */
  8. l/=1000;
  9. l=(l+50000000)/100000000;
  10. unit='T';
  11. } else if (l>1000000000) {
  12. l=(l+50000000)/100000000;
  13. unit='G';
  14. } else if (l>1000000) {
  15. l=(l+50000)/100000;
  16. unit='M';
  17. } else {
  18. l=(l+50)/100;
  19. unit='k';
  20. }
  21. if (!dest) return fmt_ulong(0,l)+2;
  22. i=fmt_ulong(dest,l/10);
  23. dest[i]='.';
  24. dest[i+1]=(char)((l%10)+'0');
  25. dest[i+2]=unit;
  26. return i+3;
  27. }