about summary refs log tree commit diff
path: root/stdio-common/tst-ungetc.c
diff options
context:
space:
mode:
Diffstat (limited to 'stdio-common/tst-ungetc.c')
-rw-r--r--stdio-common/tst-ungetc.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/stdio-common/tst-ungetc.c b/stdio-common/tst-ungetc.c
new file mode 100644
index 0000000000..67c45d4028
--- /dev/null
+++ b/stdio-common/tst-ungetc.c
@@ -0,0 +1,42 @@
+/* Test for ungetc bugs.  */
+
+#include <stdio.h>
+
+#define assert(x) \
+  if (!(x)) \
+    { \
+      fputs ("test failed: " #x "\n", stderr); \
+      retval = 1; \
+      goto the_end; \
+    }
+
+int
+main (int argc, char *argv[])
+{
+  char *name;
+  FILE *fp = NULL;
+  int retval = 0;
+  int c;
+
+  name = tmpnam (NULL);
+  fp = fopen (name, "w");
+  assert (fp != NULL)
+  fputs ("bl", fp);
+  fclose (fp);
+  fp = NULL;
+
+  fp = fopen (name, "r");
+  assert (fp != NULL)
+  assert (getc (fp) != EOF);
+  assert ((c = getc (fp)) != EOF);
+  assert (getc (fp) == EOF);
+  assert (ungetc (c, fp) == c);
+  assert (feof (fp) == 0);
+
+the_end:
+  if (fp != NULL)
+    fclose (fp);
+  unlink (name);
+
+  return retval;
+}