tst-strlen.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. do_test (void)
  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. {
  30. printf ("\
  31. strlen failed for base=%Zu, words=%Zu, and last=%Zu (is %zd, expected %zd)\n",
  32. base, words, last,
  33. strlen (buf), words * 4 + lens[last]);
  34. return 1;
  35. }
  36. if (strnlen (buf, -1) != words * 4 + lens[last])
  37. {
  38. printf ("\
  39. strnlen failed for base=%Zu, words=%Zu, and last=%Zu (is %zd, expected %zd)\n",
  40. base, words, last,
  41. strnlen (buf, -1), words * 4 + lens[last]);
  42. return 1;
  43. }
  44. }
  45. }
  46. }
  47. return 0;
  48. }
  49. #include <support/test-driver.c>