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.
 
 
 
 

25 lines
668 B

  1. #include "fmt.h"
  2. /* write int in least amount of bytes, return number of bytes */
  3. /* as used in varints from Google protocol buffers */
  4. size_t fmt_varint(char* dest,unsigned long long l) {
  5. /* high bit says if more bytes are coming, lower 7 bits are payload; little endian */
  6. size_t i;
  7. for (i=0; l; ++i, l>>=7) {
  8. if (dest) dest[i]=(l&0x7f) | ((!!(l&~0x7f))<<7);
  9. }
  10. if (!i) { /* l was 0 */
  11. if (dest) dest[0]=0;
  12. ++i;
  13. }
  14. return i;
  15. }
  16. #ifdef __ELF__
  17. size_t fmt_pb_type0_int(char* dest,unsigned long long l) __attribute__((alias("fmt_varint")));
  18. #else
  19. size_t fmt_pb_type0_int(char* dest,unsigned long long l) {
  20. return fmt_varint(dest,l);
  21. }
  22. #endif