]> pd.if.org Git - pdclib/blob - functions/string/strnlen.c
Cosmetic comment fixes.
[pdclib] / functions / string / strnlen.c
1 /* strnlen( const char *, size_t len )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <string.h>
8 #include <stdint.h>
9
10 #ifndef REGTEST
11
12 size_t strnlen( const char * s, size_t maxlen )
13 {
14     for( size_t len = 0; len != maxlen; len++ )
15     {
16         if(s[len] == '\0')
17             return len;
18     }
19     return maxlen;
20 }
21
22 #endif
23
24 #ifdef TEST
25 #include "_PDCLIB_test.h"
26
27 int main( void )
28 {
29 #ifndef REGTEST
30     TESTCASE( strnlen( abcde, 5 ) == 5 );
31     TESTCASE( strnlen( abcde, 3 ) == 3 )
32     TESTCASE( strnlen( "", SIZE_MAX ) == 0 );
33 #endif
34     return TEST_RESULTS;
35 }
36 #endif