Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strnlen.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
3
*
4
* Permission to use, copy, modify, and distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
7
*
8
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
*/
16
17
/* $OpenBSD: strnlen.c,v 1.6 2015/08/31 02:53:57 guenther Exp $ */
18
19
#include <
string.h
>
20
21
size_t
strnlen
(
const
char
* str,
size_t
maxlen)
22
{
23
const
char
* cp;
24
25
for
(cp = str; maxlen != 0 && *cp !=
'\0'
; cp++, maxlen--)
26
{
27
{
28
;
29
}
30
}
31
32
return
(
size_t
)(cp - str);
33
}
string.h
strnlen
size_t strnlen(const char *str, size_t maxlen)
Returns the length of the given null-terminated byte string.
Definition:
strnlen.c:21
src
string
strnlen.c
Generated by
1.8.15