1
/* $Id: memrchr_P.c,v 1.1.2.1 2008/03/20 21:42:30 joerg_wunsch Exp $ */
4
# define _GNU_SOURCE /* to include memrchr() */
5
# define PRINTFLN(line, fmt, ...) \
6
printf("\nLine %d: " fmt "\n", line, ##__VA_ARGS__)
7
# define EXIT(code) exit ((code) < 255 ? (code) : 255)
8
# define memrchr_P memrchr
10
# if defined(__AVR_ATmega128__)
11
/* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
12
# define PRINTFLN(line, fmt, ...) \
13
sprintf ((char *)0x2000, "\nLine %d: " fmt "\n", line, ##__VA_ARGS__)
16
# define PRINTFLN(args...)
26
void Check (int line, const char *s, int c, size_t len, int expect)
30
p = memrchr_P (s, c, len);
34
PRINTFLN (line, "non zero pointer is returned");
38
if (p != s + expect) {
39
PRINTFLN (line, "expect= %d result= %d", expect, p - s);
45
#define CHECK(s, c, len, expect) do { \
46
Check (__LINE__, PSTR(s), c, len, expect); \
53
CHECK ("", 255, 0, -1);
54
CHECK ("ABCDEF", 'a', 6, -1);
57
CHECK ("\000", 0, 1, 0);
58
CHECK ("\001", 1, 1, 0);
59
CHECK ("\377", 255, 1, 0);
60
CHECK ("987654321", '7', 9, 2);
62
/* '\0' has't a special sense */
63
CHECK ("12345", 0, 6, 5);
64
CHECK (".\000.", 0, 3, 1);
65
CHECK ("\000a\000b", 'b', 4, 3);
68
CHECK ("abcdabcd", 'b', 8, 5);
69
CHECK ("........", '.', 8, 7);
71
/* 'c' converted to a char */
72
CHECK ("ABCDEF", 'A'+0x100, 6, 0);
73
CHECK ("ABCDE\377", ~0, 6, 5);
75
/* Very long string */
76
CHECK ("................................................................"
77
"................................................................"
78
"................................................................"
79
"...............................................................*"
80
"................................................................",
82
CHECK ("................................................................"
83
"................................................................"
84
"................................................................"
85
"................................................................"
86
"*...............................................................",
88
CHECK ("................................................................"
89
"................................................................"
90
"................................................................"
91
"................................................................"
92
".*..............................................................",