1 /* Test for ungetc bugs. */
11 fputs ("test failed: " #x "\n", stderr); \
17 main (int argc
, char *argv
[])
19 char name
[] = "/tmp/tst-ungetc.XXXXXX";
25 int fd
= mkstemp (name
);
28 printf ("mkstemp failed: %m\n");
32 fp
= fopen (name
, "w");
38 fp
= fopen (name
, "r");
40 assert (ungetc ('z', fp
) == 'z');
41 assert (getc (fp
) == 'z');
42 assert (getc (fp
) == 'b');
43 assert (getc (fp
) == 'l');
44 assert (ungetc ('m', fp
) == 'm');
45 assert (getc (fp
) == 'm');
46 assert ((c
= getc (fp
)) == 'a');
47 assert (getc (fp
) == EOF
);
48 assert (ungetc (c
, fp
) == c
);
49 assert (feof (fp
) == 0);
50 assert (getc (fp
) == c
);
51 assert (getc (fp
) == EOF
);
55 fp
= fopen (name
, "r");
57 assert (getc (fp
) == 'b');
58 assert (getc (fp
) == 'l');
59 assert (ungetc ('b', fp
) == 'b');
60 assert (fread (buffer
, 1, 64, fp
) == 2);
61 assert (buffer
[0] == 'b');
62 assert (buffer
[1] == 'a');