1
/* Test of scanf(): NUL symbol (input file).
2
$Id: scanf_brk-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
const char *getpnt, *getend;
48
return pgm_read_byte (getpnt++);
51
ssize_t uread (void *cookie, char *buf, size_t size)
55
for (n = 0; n < size; n++) {
56
int i = ugetc (cookie);
63
int uclose (void *cookie)
69
static FILE * uopen (const char *buf, int size)
76
fp = fdevopen (0, ugetc);
79
cookie_io_functions_t iofuns;
80
memset (& iofuns, 0, sizeof(iofuns));
82
iofuns.close = uclose;
83
fp = fopencookie (NULL, "rb", iofuns);
99
memset (&v, ~0, sizeof(v));
100
fp = uopen (PSTR ("A\000BC"), 4);
101
i = fscanf (fp, "%[A-Z]%s", v.s, v.t);
103
ASSERT (!memcmp_P (v.s, PSTR("A"), 2));
104
ASSERT (!memcmp_P (v.t, PSTR("\000BC"), 4));
107
memset (&v, ~0, sizeof(v));
108
fp = uopen (PSTR ("D\000EF"), 4);
109
vrslt = fscanf (fp, "%[^F]%s", v.s, v.t);
111
ASSERT (!memcmp_P (v.s, PSTR("D\000E"), 4));
112
ASSERT (!memcmp_P (v.t, PSTR("F"), 2));