On Fri, Oct 20, 2017 at 04:44:58PM -0700, Richard Henderson wrote: > On 10/20/2017 10:55 AM, John Arbuckle wrote: > > +static inline size_t strnlen(const char *string, size_t max_count) > > +{ > > + size_t count; > > + for (count = 0; count < max_count; count++) { > > + if (string[count] == '\0') { > > + break; > > + } > > + } > > + return count; > > Not to nitpick, but > > const char *p = memchr(string, 0, max_count); > return p ? max_count : p - string; Richard's right, that's definitely a better implementation. -- David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Attachment:
signature.asc
Description: PGP signature