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 |
|
---|
8 | #ifndef HAVE_STRNLEN
|
---|
9 | static inline size_t strnlen(const char *psz, size_t cch)
|
---|
10 | {
|
---|
11 | const char *psz2 = psz;
|
---|
12 | while (cch > 0 && *psz)
|
---|
13 | cch--, psz++;
|
---|
14 | return psz - psz2;
|
---|
15 | }
|
---|
16 | #endif
|
---|
17 |
|
---|
18 | int
|
---|
19 | main(int argc, char *argv[])
|
---|
20 | {
|
---|
21 | static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
|
---|
22 | 0, 1, 0, 2, 0, 1, 0, 4 };
|
---|
23 | char basebuf[24 + 32];
|
---|
24 | size_t base;
|
---|
25 |
|
---|
26 | for (base = 0; base < 32; ++base)
|
---|
27 | {
|
---|
28 | char *buf = basebuf + base;
|
---|
29 | size_t words;
|
---|
30 |
|
---|
31 | for (words = 0; words < 4; ++words)
|
---|
32 | {
|
---|
33 | size_t last;
|
---|
34 | memset (buf, 'a', words * 4);
|
---|
35 |
|
---|
36 | for (last = 0; last < 16; ++last)
|
---|
37 | {
|
---|
38 | buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
|
---|
39 | buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
|
---|
40 | buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
|
---|
41 | buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
|
---|
42 | buf[words * 4 + 4] = '\0';
|
---|
43 |
|
---|
44 | if (strlen (buf) != words * 4 + lens[last]
|
---|
45 | || strnlen (buf, -1) != words * 4 + lens[last])
|
---|
46 | {
|
---|
47 | printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n",
|
---|
48 | base, words, last);
|
---|
49 | return 1;
|
---|
50 | }
|
---|
51 | }
|
---|
52 | }
|
---|
53 | }
|
---|
54 | return 0;
|
---|
55 | }
|
---|