srsran_vec_sprint_hex returns number of written characters

master
Xavier Arteaga 4 years ago committed by Andre Puschmann
parent 3634e96c3e
commit bcb91d6173

@ -131,7 +131,7 @@ SRSRAN_API void srsran_vec_fprint_byte(FILE* stream, const uint8_t* x, const uin
SRSRAN_API void srsran_vec_fprint_i(FILE* stream, const int* x, const uint32_t len);
SRSRAN_API void srsran_vec_fprint_s(FILE* stream, const int16_t* x, const uint32_t len);
SRSRAN_API void srsran_vec_fprint_hex(FILE* stream, uint8_t* x, const uint32_t len);
SRSRAN_API void srsran_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, const uint32_t len);
SRSRAN_API uint32_t srsran_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, const uint32_t len);
SRSRAN_API void srsran_vec_sprint_bin(char* str, const uint32_t max_str_len, const uint8_t* x, const uint32_t len);
/* Saves/loads a vector to a file */

@ -354,7 +354,7 @@ void srsran_vec_fprint_hex(FILE* stream, uint8_t* x, const uint32_t len)
fprintf(stream, "];\n");
}
void srsran_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, const uint32_t len)
uint32_t srsran_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, const uint32_t len)
{
uint32_t i, nbytes;
uint8_t byte;
@ -362,7 +362,7 @@ void srsran_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, co
// check that hex string fits in buffer (every byte takes 3 characters, plus brackets)
if ((3 * (len / 8 + ((len % 8) ? 1 : 0))) + 2 >= max_str_len) {
ERROR("Buffer too small for printing hex string (max_str_len=%d, payload_len=%d).", max_str_len, len);
return;
return 0;
}
int n = 0;
@ -376,7 +376,10 @@ void srsran_vec_sprint_hex(char* str, const uint32_t max_str_len, uint8_t* x, co
n += sprintf(&str[n], "%02x ", byte);
}
n += sprintf(&str[n], "]");
str[n] = 0;
str[max_str_len - 1] = 0;
return n;
}
void srsran_vec_sprint_bin(char* str, const uint32_t max_str_len, const uint8_t* x, const uint32_t len)

Loading…
Cancel
Save