1
/* $Id: strchrnul_P.c,v 1.1.2.1 2008/03/20 21:42:30 joerg_wunsch Exp $ */
4
# define _GNU_SOURCE /* to include strchrnul() */
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 strchrnul_P strchrnul
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, int expect)
30
p = strchrnul_P (s, c);
32
if (p != s + expect) {
33
PRINTFLN (line, "expect: %d, result: %d", expect, p - s);
38
#define CHECK(s, c, expect) do { \
39
Check (__LINE__, PSTR(s), c, expect); \
47
CHECK ("ABCDEF", 'a', 6);
51
CHECK ("\377", 255, 0);
52
CHECK ("987654321", '7', 2);
54
/* '\0' is a part of string */
55
CHECK ("12345", 0, 5);
59
CHECK ("abcdabcd", 'b', 1);
61
/* 'c' converted to a char */
62
CHECK ("ABCDEF", 'A'+0x100, 0);
63
CHECK ("ABCDE\377", ~0, 5);
65
/* Very long string */
66
CHECK ("................................................................"
67
"................................................................"
68
"................................................................"
69
"...............................................................*"
70
"...............", '*', 255);
71
CHECK ("................................................................"
72
"................................................................"
73
"................................................................"
74
"................................................................"
75
"*..............", '*', 256);
76
CHECK ("................................................................"
77
"................................................................"
78
"................................................................"
79
"................................................................"
80
".*.............", '*', 257);