memcmp.c 424 B

12345678910111213141516171819202122232425
  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. int memcmp(const void *s1, const void *s2, size_t len)
  9. {
  10. const unsigned char *s = s1;
  11. const unsigned char *d = s2;
  12. unsigned char sc;
  13. unsigned char dc;
  14. while (len--) {
  15. sc = *s++;
  16. dc = *d++;
  17. if (sc - dc)
  18. return (sc - dc);
  19. }
  20. return 0;
  21. }