source: vendor/glibc-tests/glibc/string/tst-strlen.c

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 1.1 KB
Line 
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
5#include <stdio.h>
6#include <string.h>
7
8int
9main(int argc, char *argv[])
10{
11 static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
12 0, 1, 0, 2, 0, 1, 0, 4 };
13 char basebuf[24 + 32];
14 size_t base;
15
16 for (base = 0; base < 32; ++base)
17 {
18 char *buf = basebuf + base;
19 size_t words;
20
21 for (words = 0; words < 4; ++words)
22 {
23 size_t last;
24 memset (buf, 'a', words * 4);
25
26 for (last = 0; last < 16; ++last)
27 {
28 buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
29 buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
30 buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
31 buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
32 buf[words * 4 + 4] = '\0';
33
34 if (strlen (buf) != words * 4 + lens[last]
35 || strnlen (buf, -1) != words * 4 + lens[last])
36 {
37 printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n",
38 base, words, last);
39 return 1;
40 }
41 }
42 }
43 }
44 return 0;
45}
Note: See TracBrowser for help on using the repository browser.