tst-strlen.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* Make sure we don't test the optimized inline functions if we want to
  2. test the real implementation. */
  3. #undef __USE_STRING_INLINES
  4. #include <stdio.h>
  5. #include <string.h>
  6. int
  7. main(int argc, char *argv[])
  8. {
  9. static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
  10. 0, 1, 0, 2, 0, 1, 0, 4 };
  11. char basebuf[24 + 32];
  12. size_t base;
  13. for (base = 0; base < 32; ++base)
  14. {
  15. char *buf = basebuf + base;
  16. size_t words;
  17. for (words = 0; words < 4; ++words)
  18. {
  19. size_t last;
  20. memset (buf, 'a', words * 4);
  21. for (last = 0; last < 16; ++last)
  22. {
  23. buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
  24. buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
  25. buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
  26. buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
  27. buf[words * 4 + 4] = '\0';
  28. if (strlen (buf) != words * 4 + lens[last]
  29. || strnlen (buf, -1) != words * 4 + lens[last])
  30. {
  31. printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n",
  32. base, words, last);
  33. return 1;
  34. }
  35. }
  36. }
  37. }
  38. return 0;
  39. }