memeq.c 564 B

12345678910111213141516171819202122
  1. // SPDX-License-Identifier: GPL-2.0 or GPL-3.0
  2. // Copyright © 2019 Ariadne Devos
  3. #include <stddef.h>
  4. #include <sHT/index.h>
  5. #include <sHT/string.h>
  6. #include <sHT/test.h>
  7. size_t
  8. sHT_memeq(const char *buffer0, const char *buffer1, size_t correct, size_t otherwise, size_t length)
  9. {
  10. size_t i;
  11. /* TODO: optimise -- but without Spectre issues
  12. Perhaps do a word at a time. */
  13. sHT_index_iterate(i, length) {
  14. /* @var{sHT_and_none} is incorrect here! Strings can contain NUL. */
  15. if (sHT_neq(buffer0[i], buffer1[i]))
  16. return otherwise;
  17. }
  18. return correct;
  19. }