memchr.c 351 B

123456789101112131415161718192021
  1. /*
  2. * Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stddef.h>
  7. #include <string.h>
  8. void *memchr(const void *src, int c, size_t len)
  9. {
  10. const unsigned char *s = src;
  11. while (len--) {
  12. if (*s == (unsigned char)c)
  13. return (void *) s;
  14. s++;
  15. }
  16. return NULL;
  17. }