Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

45 lines
759 B

/*
* 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;
}