1*5ba6b03cSchristos /* Portable version of strnlen. 2*5ba6b03cSchristos This function is in the public domain. */ 3*5ba6b03cSchristos 4*5ba6b03cSchristos /* 5*5ba6b03cSchristos 6*5ba6b03cSchristos @deftypefn Supplemental size_t strnlen (const char *@var{s}, size_t @var{maxlen}) 7*5ba6b03cSchristos 8*5ba6b03cSchristos Returns the length of @var{s}, as with @code{strlen}, but never looks 9*5ba6b03cSchristos past the first @var{maxlen} characters in the string. If there is no 10*5ba6b03cSchristos '\0' character in the first @var{maxlen} characters, returns 11*5ba6b03cSchristos @var{maxlen}. 12*5ba6b03cSchristos 13*5ba6b03cSchristos @end deftypefn 14*5ba6b03cSchristos 15*5ba6b03cSchristos */ 16*5ba6b03cSchristos 17*5ba6b03cSchristos #include "config.h" 18*5ba6b03cSchristos 19*5ba6b03cSchristos #include <stddef.h> 20*5ba6b03cSchristos 21*5ba6b03cSchristos size_t strnlen(const char * s,size_t maxlen)22*5ba6b03cSchristosstrnlen (const char *s, size_t maxlen) 23*5ba6b03cSchristos { 24*5ba6b03cSchristos size_t i; 25*5ba6b03cSchristos 26*5ba6b03cSchristos for (i = 0; i < maxlen; ++i) 27*5ba6b03cSchristos if (s[i] == '\0') 28*5ba6b03cSchristos break; 29*5ba6b03cSchristos return i; 30*5ba6b03cSchristos } 31