diff options
author | DJ Delorie <dj@redhat.com> | 2012-10-10 03:11:33 +0000 |
---|---|---|
committer | DJ Delorie <dj@redhat.com> | 2012-10-10 03:11:33 +0000 |
commit | 995b61fe5b880e79b767160207fd363b125fdaa3 (patch) | |
tree | 47dc5239563a2d1ab75ea7790c9ce51baf80a821 /libiberty/strnlen.c | |
parent | fd49b9b373ee89cd57fcd4d9cfd791fd4b9ebdc7 (diff) | |
download | gdb-995b61fe5b880e79b767160207fd363b125fdaa3.zip gdb-995b61fe5b880e79b767160207fd363b125fdaa3.tar.gz gdb-995b61fe5b880e79b767160207fd363b125fdaa3.tar.bz2 |
merge from gcc
Diffstat (limited to 'libiberty/strnlen.c')
-rw-r--r-- | libiberty/strnlen.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libiberty/strnlen.c b/libiberty/strnlen.c new file mode 100644 index 0000000..4934973 --- /dev/null +++ b/libiberty/strnlen.c @@ -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; +} |