1
/* $Id: memchr.c,v 1.1 2007/03/01 13:10:55 dmix Exp $ */
10
void Check (int line, const char *s, int c, size_t len, int expect)
18
p = memchr (t, c, len);
19
if ((expect == -1 && !p) || (t + expect == p))
22
printf ("\nLine %d: expect: %d, result: %d\n",
23
line, expect, (p ? p-t : -1));
24
if (line > 255) line = 255; /* common OS restriction */
29
#define CHECK(s, c, len, expect) do { \
30
Check (__LINE__, PSTR(s), c, len, expect); \
37
CHECK ("", 255, 0, -1);
38
CHECK ("ABCDEF", 'a', 6, -1);
41
CHECK ("\000", 0, 1, 0);
42
CHECK ("\001", 1, 1, 0);
43
CHECK ("\377", 255, 1, 0);
44
CHECK ("987654321", '7', 9, 2);
46
/* '\0' has't a special sense */
47
CHECK ("12345", 0, 6, 5);
48
CHECK (".\000.", 0, 3, 1);
49
CHECK ("\000a\000b", 'b', 4, 3);
52
CHECK ("abcdabcd", 'b', 8, 1);
53
CHECK ("........", '.', 8, 0);
55
/* 'c' converted to a char */
56
CHECK ("ABCDEF", 'A'+0x100, 6, 0);
57
CHECK ("ABCDE\377", ~0, 6, 5);
59
/* Very long string */
60
CHECK ("................................................................"
61
"................................................................"
62
"................................................................"
63
"................................................................"
64
"*...............................................................",