Update.
[glibc.git] / stdio-common / tst-ungetc.c
blob08819b77658af6f69302d7240578bb9c5b098b70
1 /* Test for ungetc bugs. */
3 #include <stdio.h>
4 #include <unistd.h>
6 #define assert(x) \
7 if (!(x)) \
8 { \
9 fputs ("test failed: " #x "\n", stderr); \
10 retval = 1; \
11 goto the_end; \
14 int
15 main (int argc, char *argv[])
17 char *name;
18 FILE *fp = NULL;
19 int retval = 0;
20 int c;
22 name = tmpnam (NULL);
23 fp = fopen (name, "w");
24 assert (fp != NULL)
25 fputs ("bla", fp);
26 fclose (fp);
27 fp = NULL;
29 fp = fopen (name, "r");
30 assert (fp != NULL);
31 assert (ungetc ('z', fp) == 'z');
32 assert (getc (fp) == 'z');
33 assert (getc (fp) == 'b');
34 assert (getc (fp) == 'l');
35 assert (ungetc ('m', fp) == 'm');
36 assert (getc (fp) == 'm');
37 assert ((c = getc (fp)) == 'a');
38 assert (getc (fp) == EOF);
39 assert (ungetc (c, fp) == c);
40 assert (feof (fp) == 0);
41 assert (getc (fp) == c);
42 assert (getc (fp) == EOF);
44 the_end:
45 if (fp != NULL)
46 fclose (fp);
47 unlink (name);
49 return retval;