zephyr/lib/libc/common/source/string/strnlen.c
Kumar Gala ca4dc50ec1 libc: Move strnlen into common
Move the strnlen implementation into common so its available to any
libc that may not implement strnlen.

Signed-off-by: Kumar Gala <kumar.gala@intel.com>
2023-05-08 09:59:27 +02:00

32 lines
515 B
C

/*
* Copyright (c) 2014 Wind River Systems, Inc.
* Copyright (c) 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
/**
*
* @brief Get fixed-size string length
*
* This function is not available in ARM C Standard library.
*
* @return number of bytes in fixed-size string <s>
*/
size_t strnlen(const char *s, size_t maxlen)
{
size_t n = 0;
while (*s != '\0' && n < maxlen) {
s++;
n++;
}
return n;
}