blob: 36b35712f6c7318ec92fc6f7182c1a3f918abd0c [file] [log] [blame]
Jit Loon Lim012a9d92025-03-17 16:25:53 +08001/*
2 * Copyright (c) 2024-2025, Altera Corporation. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <string.h>
8
9size_t strnlen_secure(const char *str, size_t maxlen)
10{
11 size_t len = 0;
12
13 if (str == NULL) {
14 return 0;
15 }
16
17 while ((len < maxlen) && (str[len] != '\0')) {
18 len++;
19 }
20
21 return len;
22}