mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 03:47:02 -05:00
strnlen.c: New file.
* strnlen.c: New file. * configure.ac: Check for strnlen, add it to AC_LIBOBJ if it's not present. * Makefile.in: Rebuild dependencies. (CFILES): Add strnlen.c. (CONFIGURED_OFILES): Add ./strnlen.$(objext). * configure, config.in, functions.texi: Rebuild. * maint-tool: Accept .def files in the include directory. From-SVN: r191432
This commit is contained in:
committed by
Ian Lance Taylor
parent
fb5e0707d1
commit
9a9baa5254
30
libiberty/strnlen.c
Normal file
30
libiberty/strnlen.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* Portable version of strnlen.
|
||||
This function is in the public domain. */
|
||||
|
||||
/*
|
||||
|
||||
@deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen})
|
||||
|
||||
Returns the length of @var{s}, as with @code{strlen}, but never looks
|
||||
past the first @var{maxlen} characters in the string. If there is no
|
||||
'\0' character in the first @var{maxlen} characters, returns
|
||||
@var{maxlen}.
|
||||
|
||||
@end deftypefn
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
size_t
|
||||
strnlen (const char *s, size_t maxlen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < maxlen; ++i)
|
||||
if (s[i] == '\0')
|
||||
break;
|
||||
return i;
|
||||
}
|
||||
Reference in New Issue
Block a user