This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20 #include <string.h>
21
22 #include "signature.h"
23 SIGNATURE_CHECK (strchrnul, char *, (char const *, int));
24
25 #include <stdlib.h>
26
27 #include "macros.h"
28
29 int
30 main (void)
31 {
32 size_t n = 0x100000;
33 char *input = malloc (n + 1);
34 ASSERT (input);
35
36 input[0] = 'a';
37 input[1] = 'b';
38 memset (input + 2, 'c', 1024);
39 memset (input + 1026, 'd', n - 1028);
40 input[n - 2] = 'e';
41 input[n - 1] = 'a';
42 input[n] = '\0';
43
44
45 ASSERT (strchrnul (input, 'a') == input);
46 ASSERT (strchrnul (input, 'b') == input + 1);
47 ASSERT (strchrnul (input, 'c') == input + 2);
48 ASSERT (strchrnul (input, 'd') == input + 1026);
49
50 ASSERT (strchrnul (input + 1, 'a') == input + n - 1);
51 ASSERT (strchrnul (input + 1, 'e') == input + n - 2);
52
53 ASSERT (strchrnul (input, 'f') == input + n);
54 ASSERT (strchrnul (input, '\0') == input + n);
55
56
57
58 {
59 size_t repeat = 10000;
60 for (; repeat > 0; repeat--)
61 {
62 ASSERT (strchrnul (input, 'c') == input + 2);
63 }
64 }
65
66
67 {
68 int i, j;
69 for (i = 0; i < 32; i++)
70 {
71 for (j = 0; j < 256; j++)
72 input[i + j] = (j + 1) & 0xff;
73 for (j = 1; j < 256; j++)
74 {
75 ASSERT (strchrnul (input + i, j) == input + i + j - 1);
76 input[i + j - 1] = (j == 1 ? 2 : 1);
77 ASSERT (strchrnul (input + i, j) == input + i + 255);
78 input[i + j - 1] = j;
79 }
80 }
81 }
82
83 free (input);
84
85 return 0;
86 }