aboutsummaryrefslogtreecommitdiff
path: root/string/tst-strlen.c
blob: 4acd4045f522185f7fdc233e051bcfde4c205699 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <string.h>

int
main(int argc, char *argv[])
{
  static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
				 0, 1, 0, 2, 0, 1, 0, 4 };
  char basebuf[24 + 32];
  size_t base;

  for (base = 0; base < 32; ++base)
    {
      char *buf = basebuf + base;
      size_t words;

      for (words = 0; words < 4; ++words)
	{
	  size_t last;
	  memset (buf, 'a', words * 4);

	  for (last = 0; last < 16; ++last)
	    {
	      buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
	      buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
	      buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
	      buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
	      buf[words * 4 + 4] = '\0';

	      if (strlen (buf) != words * 4 + lens[last])
		{
		  printf ("failed for base=%d, words=%d, and last=%d\n",
			  base, words, last);
		  return 1;
		}
	    }
	}
    }
  return 0;
}