5 #include "../../config.h"
7 /* mallocs an mem block and fills it with A. A needs to be a zero
8 terminated string. The A string chars, minus the terminating zero
9 are copied into the returned mem block. */
11 create_mem (const char *a
)
13 size_t len
= strlen (a
);
14 void *mem
= malloc (len
);
25 haystack
= create_mem ("a");
26 needle
= create_mem ("a");
27 #if defined(VGO_darwin) || defined(VGO_solaris)
30 * If big_len is smaller than little_len, if little_len is 0, if big_len is 0 or if
31 * little occurs nowhere in big, NULL is returned; otherwise a pointer to the first
32 * character of the first occurrence of little is returned.
34 assert (memmem (haystack
, 0, needle
, 0) == NULL
);
35 assert (memmem (haystack
, 1, needle
, 0) == NULL
);
37 assert (memmem (haystack
, 0, needle
, 0) == haystack
);
38 assert (memmem (haystack
, 1, needle
, 0) == haystack
);
40 assert (memmem (haystack
, 0, needle
, 1) == NULL
);
41 assert (memmem (haystack
, 1, needle
, 1) == haystack
);
45 haystack
= create_mem ("abc");
46 needle
= create_mem ("bc");
47 #if defined(VGO_darwin) || defined(VGO_solaris)
48 assert (memmem (haystack
, 3, needle
, 0) == NULL
);
50 assert (memmem (haystack
, 3, needle
, 0) == haystack
);
52 assert (memmem (haystack
, 3, needle
, 2) == haystack
+ 1);
53 assert (memmem (haystack
+ 1, 2, needle
, 2) == haystack
+ 1);
54 assert (memmem (haystack
+ 2, 1, needle
, 2) == NULL
);
58 haystack
= create_mem ("abcabcabc");
59 needle
= create_mem ("bca");
60 assert (memmem (haystack
, 9, needle
, 3) == haystack
+ 1);
64 haystack
= create_mem ("abcabcabc");
65 needle
= create_mem ("bcad");
66 assert (memmem (haystack
, 9, needle
, 4) == NULL
);
70 haystack
= create_mem ("xxxxxxxxxxxxxxxxxABC");
71 needle
= create_mem ("ABCD");
72 assert (memmem (haystack
, 20, needle
, 2) == haystack
+ 17);
73 assert (memmem (haystack
+ 3, 17, needle
, 2) == haystack
+ 17);
74 assert (memmem (haystack
+ 15, 5, needle
, 2) == haystack
+ 17);
75 assert (memmem (haystack
, 20, needle
, 3) == haystack
+ 17);
76 assert (memmem (haystack
+ 3, 17, needle
, 3) == haystack
+ 17);
77 assert (memmem (haystack
+ 15, 5, needle
, 3) == haystack
+ 17);
78 assert (memmem (haystack
, 20, needle
, 4) == NULL
);
79 assert (memmem (haystack
+ 3, 5, needle
, 4) == NULL
);
80 assert (memmem (haystack
+ 15, 5, needle
, 4) == NULL
);