strnlen.c 308 B

12345678910111213
  1. /*
  2. * Copyright (c) 2005-2014 Rich Felker, et al.
  3. * Copyright (c) 2015-2016 HarveyOS et al.
  4. *
  5. * Use of this source code is governed by a MIT-style
  6. * license that can be found in the LICENSE.mit file.
  7. */
  8. size_t strnlen(const char *s, size_t n)
  9. {
  10. const char *p = memchr(s, 0, n);
  11. return p ? p-s : n;
  12. }