Update.
[glibc.git] / stdio-common / tst-ungetc.c
blobba74a84f7f015b0f683578da71f57c8340f4a389
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 ("bl", fp);
26 fclose (fp);
27 fp = NULL;
29 fp = fopen (name, "r");
30 assert (fp != NULL)
31 assert (getc (fp) != EOF);
32 assert ((c = getc (fp)) != EOF);
33 assert (getc (fp) == EOF);
34 assert (ungetc (c, fp) == c);
35 assert (feof (fp) == 0);
37 the_end:
38 if (fp != NULL)
39 fclose (fp);
40 unlink (name);
42 return retval;