*** empty log message ***
[glibc.git] / stdio-common / tst-ungetc.c
blob67c45d4028394018cf017649eec5a60da2e1594e
1 /* Test for ungetc bugs. */
3 #include <stdio.h>
5 #define assert(x) \
6 if (!(x)) \
7 { \
8 fputs ("test failed: " #x "\n", stderr); \
9 retval = 1; \
10 goto the_end; \
13 int
14 main (int argc, char *argv[])
16 char *name;
17 FILE *fp = NULL;
18 int retval = 0;
19 int c;
21 name = tmpnam (NULL);
22 fp = fopen (name, "w");
23 assert (fp != NULL)
24 fputs ("bl", fp);
25 fclose (fp);
26 fp = NULL;
28 fp = fopen (name, "r");
29 assert (fp != NULL)
30 assert (getc (fp) != EOF);
31 assert ((c = getc (fp)) != EOF);
32 assert (getc (fp) == EOF);
33 assert (ungetc (c, fp) == c);
34 assert (feof (fp) == 0);
36 the_end:
37 if (fp != NULL)
38 fclose (fp);
39 unlink (name);
41 return retval;