add tls_init_dlopen test and fix tls_align_dlopen.mk so it is run properly
[libc-test] / src / functional / string_strchr.c
1 #include <string.h>
2 #include "test.h"
3
4 #define N(s, c) { \
5         char *p = s; \
6         char *q = strchr(p, c); \
7         if (q) \
8                 t_error("strchr(%s,%s) returned str+%d, wanted 0\n", #s, #c, q-p); \
9 }
10
11 #define T(s, c, n) { \
12         char *p = s; \
13         char *q = strchr(p, c); \
14         if (q == 0) \
15                 t_error("strchr(%s,%s) returned 0, wanted str+%d\n", #s, #c, n); \
16         else if (q - p != n) \
17                 t_error("strchr(%s,%s) returned str+%d, wanted str+%d\n", #s, #c, q-p, n); \
18 }
19
20 int main(void)
21 {
22         int i;
23         char a[128];
24         char s[256];
25
26         for (i = 0; i < 128; i++)
27                 a[i] = (i+1) & 127;
28         for (i = 0; i < 256; i++)
29                 *((unsigned char*)s+i) = i+1;
30
31         N("", 'a')
32         N("a", 'b')
33         N("abc abc", 'x')
34         N(a, 128)
35         N(a, 255)
36
37         T("", 0, 0)
38         T("a", 'a', 0)
39         T("a", 'a'+256, 0)
40         T("a", 0, 1)
41         T("ab", 'b', 1)
42         T("aab", 'b', 2)
43         T("aaab", 'b', 3)
44         T("aaaab", 'b', 4)
45         T("aaaaab", 'b', 5)
46         T("aaaaaab", 'b', 6)
47         T("abc abc", 'c', 2)
48         T(s, 1, 0)
49         T(s, 2, 1)
50         T(s, 10, 9)
51         T(s, 11, 10)
52         T(s, 127, 126)
53         T(s, 128, 127)
54         T(s, 255, 254)
55         T(s, 0, 255)
56
57         return t_status;
58 }