1025 |
1025 |
1026 char* util_hexstr(const unsigned char *data, size_t len) { |
1026 char* util_hexstr(const unsigned char *data, size_t len) { |
1027 size_t buflen = 2*len + 4; |
1027 size_t buflen = 2*len + 4; |
1028 UcxBuffer *buf = ucx_buffer_new(malloc(buflen), buflen + 1, 0); |
1028 UcxBuffer *buf = ucx_buffer_new(malloc(buflen), buflen + 1, 0); |
1029 for(int i=0;i<len;i++) { |
1029 for(int i=0;i<len;i++) { |
1030 ucx_bprintf(buf, "%x", data[i]); |
1030 ucx_bprintf(buf, "%02x", data[i]); |
1031 } |
1031 } |
1032 ucx_buffer_putc(buf, 0); |
1032 ucx_buffer_putc(buf, 0); |
1033 char *str = buf->space; |
1033 char *str = buf->space; |
1034 ucx_buffer_free(buf); |
1034 ucx_buffer_free(buf); |
1035 return str; |
1035 return str; |