| /* |
| * Copyright (c) 2025 Nordic Semiconductor ASA |
| * |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| /** |
| * @file |
| * This file provides utility functions for the OpenThread module. |
| * |
| */ |
| |
| #include <stddef.h> |
| #include <string.h> |
| #include <ctype.h> |
| #include <stdlib.h> |
| #include <errno.h> |
| |
| #include <openthread_utils.h> |
| |
| int bytes_from_str(uint8_t *buf, int buf_len, const char *src) |
| { |
| if (!buf || !src) { |
| return -EINVAL; |
| } |
| |
| size_t i; |
| size_t src_len = strlen(src); |
| char *endptr; |
| |
| for (i = 0U; i < src_len; i++) { |
| if (!isxdigit((unsigned char)src[i]) && src[i] != ':') { |
| return -EINVAL; |
| } |
| } |
| |
| (void)memset(buf, 0, buf_len); |
| |
| for (i = 0U; i < (size_t)buf_len; i++) { |
| buf[i] = (uint8_t)strtol(src, &endptr, 16); |
| src = ++endptr; |
| } |
| |
| return 0; |
| } |