1 int buffer_append_long_hex(buffer *b, unsigned long value) { 2 char *buf; 3 int shift = 0; 4 unsigned long copy = value; 5 6 while (copy) { 7 copy >>= 4; 8 shift++; 9 }10 if (shift == 0)11 shift++;12 if (shift & 0x01)13 shift++;14 15 buffer_prepare_append(b, shift + 1);16 if (b->used == 0)17 b->used++;18 buf = b->ptr + (b->used - 1);19 b->used += shift;20 21 shift <<= 2;22 while (shift > 0) {23 shift -= 4;24 *(buf++) = hex_chars[(value >> shift) & 0x0F];25 }26 *buf = '\0';27 28 return 0;29 }