1
/* $Id: vsnprintf_all.c,v 1.1.2.1 2008/03/20 21:42:32 joerg_wunsch Exp $ */
4
# define PRINTFLN(line, fmt, ...) \
5
printf("\nLine %2d: " fmt "\n", line, ##__VA_ARGS__)
6
# define EXIT(code) exit ((code) < 255 ? (code) : 255)
7
# define vsnprintf_P vsnprintf
9
# if defined(__AVR_ATmega128__)
10
/* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
11
# define PRINTFLN(line, fmt, ...) \
12
sprintf ((char *)0x2000, "\nLine %d: " fmt "\n", line, ##__VA_ARGS__)
15
# define PRINTFLN(args...)
20
#define L_PRINTFLN(args...) PRINTFLN (__LINE__, args)
21
#define L_EXIT() EXIT (__LINE__)
30
# define vsnprintf vsnprintf_P
31
# define PFMT(s) PSTR(s)
37
int expval, const char *expstr,
38
char *buf, size_t size, const char *fmt, ...)
45
retval = vsnprintf (buf, size, fmt, ap);
50
else if (size && strcmp_P (buf, expstr))
54
PRINTFLN (line, "expect: %3d, \"%s\",\n%8s output: %3d, \"%s\"\n",
55
strlen(expstr), expstr, " ", retval, size ? buf : "");
63
#define FILLBUF 0x55 /* Before call of function to test
64
buf[] is filled with nonzero value. */
65
#define CHECK(expval, expstr, buf, size, fmt, ...) \
66
memset (buf, FILLBUF, sizeof(buf)); \
67
Check (__LINE__, expval, PSTR(expstr), \
68
buf, size, PFMT(fmt), ##__VA_ARGS__)
76
CHECK (0, "", s+10, 0, "");
78
/* bug #19280: snprintf(s,0,...) write to s[-1] */
79
memset (s, FILLBUF, sizeof(s));
80
Check (__LINE__, 3, PSTR(""), s+10, 0, PFMT("foo"));
81
for (i = 0; i != (int)sizeof(s); i++) {
82
if ((unsigned char)s[i] != FILLBUF)
88
CHECK (0, "", s, 1, "");
89
CHECK (3, "", s, 1, "foo");
92
CHECK (0, "", s, 2, "");
93
CHECK (1, ".", s, 2, ".");
94
CHECK (2, "a", s, 2, "aa");
95
CHECK (5, "1", s, 2, "%d", 12345);
98
CHECK (6, "-12345", s, sizeof(s), "%d", -12345);
99
CHECK (5, "54321", s, ~0u >> 1, "%u", 54321); /* 32767 */
100
CHECK (4, "abcd", s, ~(~0u >> 1), "%x", 0xabcd); /* 32768 */
101
CHECK (3, "123", s, ~0u, "%o", 0123); /* 65535 */