mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
sys/fmt: add fmt_hex_bytes size probing
This commit is contained in:
parent
e272cc920b
commit
aeb1230266
@ -160,6 +160,11 @@ size_t fmt_hex_bytes(uint8_t *out, const char *hex)
|
||||
}
|
||||
|
||||
size_t final_len = len >> 1;
|
||||
|
||||
if (out == NULL) {
|
||||
return final_len;
|
||||
}
|
||||
|
||||
for (size_t i = 0, j = 0; j < final_len; i += 2, j++) {
|
||||
out[j] = fmt_hex_byte(hex + i);
|
||||
}
|
||||
|
@ -176,6 +176,9 @@ static void test_fmt_hex_bytes(void)
|
||||
TEST_ASSERT_EQUAL_INT(0, val);
|
||||
TEST_ASSERT_EQUAL_INT(0, bytes);
|
||||
|
||||
bytes = fmt_hex_bytes(NULL, "ABCDEF");
|
||||
TEST_ASSERT_EQUAL_INT(3, bytes);
|
||||
|
||||
char hex2[3] = "00";
|
||||
uint8_t val1[1] = { 0 };
|
||||
bytes = fmt_hex_bytes(val1, hex2);
|
||||
|
Loading…
Reference in New Issue
Block a user