1
/* Test of scanf(): NUL symbol (input file).
2
$Id: scanf-nul.c,v 1.1.2.3 2008/03/20 21:42:32 joerg_wunsch Exp $ */
11
# define ASSERT(expr) \
13
if (!(expr)) exit(__LINE__); \
15
# define EXIT(v) exit (v)
16
# if defined(__AVR_ATmega128__)
17
/* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
18
# define PRINTF(f...) sprintf((char *)0x2000, f)
26
# define ASSERT(expr) assert (expr)
27
# define EXIT(v) exit ((v) < 256 ? (v) : 255)
28
# define PRINTF(f...) printf (f)
29
# define sscanf_P sscanf
30
# define memcmp_P memcmp
31
# define _FDEV_EOF (-1)
34
/* Next variables are useful to debug the AVR. */
41
} v = { 1, 1, {1}, {1} };
43
const char *getpnt, *getend;
50
return pgm_read_byte (getpnt++);
53
ssize_t uread (void *cookie, char *buf, size_t size)
57
for (n = 0; n < size; n++) {
58
int i = ugetc (cookie);
65
int uclose (void *cookie)
71
static FILE * uopen (const char *buf, int size)
78
fp = fdevopen (0, ugetc);
81
cookie_io_functions_t iofuns;
82
memset (& iofuns, 0, sizeof(iofuns));
84
iofuns.close = uclose;
85
fp = fopencookie (NULL, "rb", iofuns);
101
memset (&v, ~0, sizeof(v));
102
fp = uopen (PSTR ("A\000B"), 3);
103
vrslt = fscanf (fp, "%c%c%c", v.s, v.s + 1, v.s + 2);
105
ASSERT (!memcmp_P (v.s, PSTR("A\000B"), 3));
107
/* '\0' is not a space. */
108
memset (&v, ~0, sizeof(v));
109
fp = uopen (PSTR ("\t \000"), 3);
110
i = fscanf (fp, " %c", v.s);
115
memset (&v, ~0, sizeof(v));
116
fp = uopen (PSTR ("123\000456"), 7);
117
i = fscanf (fp, "%d%c%d", & v.i, v.s, & v.j);
119
ASSERT (v.i == 123 && !v.s[0] && v.j == 456);
122
memset (&v, ~0, sizeof(v));
123
fp = uopen (PSTR ("A\000BC"), 4);
124
i = fscanf (fp, "%s%s", v.s, v.t);
126
ASSERT (!memcmp_P (v.s, PSTR("A\000BC"), 4));