humansize.h 613 B

12345678910111213141516171819202122
  1. #ifndef HUMANSIZE_H_
  2. #define HUMANSIZE_H_
  3. #include <stdint.h>
  4. /**
  5. * humansize(size):
  6. * Given a size ${size} in bytes, allocate and return a string of the form
  7. * "<N> B" for 0 <= N <= 999 or "<X> <prefix>B" where either 10 <= X <= 999 or
  8. * 1.0 <= X <= 9.9 and <prefix> is "k", "M", "G", "T", "P", or "E"; and where
  9. * the value returned is the largest valid value <= the provided size.
  10. */
  11. char * humansize(uint64_t);
  12. /**
  13. * humansize_parse(s, size):
  14. * Parse a string matching /[0-9]+ ?[kMGTPE]?B?/ as a size ${size} in bytes.
  15. */
  16. int humansize_parse(const char *, uint64_t *);
  17. #endif /* !HUMANSIZE_H_ */