regression: rewind should clear error flag
authorSzabolcs Nagy <nsz@port70.net>
Fri, 26 Jul 2013 16:47:03 +0000 (16:47 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Fri, 26 Jul 2013 16:47:03 +0000 (16:47 +0000)
src/regression/rewind-clear-error.c [new file with mode: 0644]

diff --git a/src/regression/rewind-clear-error.c b/src/regression/rewind-clear-error.c
new file mode 100644 (file)
index 0000000..e537590
--- /dev/null
@@ -0,0 +1,28 @@
+// commit: a6238c30d169cbac6bc4c4977622242063e32270 2011-02-22
+// rewind should clear error
+#include <stdio.h>
+#include <unistd.h>
+#include "test.h"
+
+int main(void)
+{
+       char buf[1];
+       size_t n;
+       int fd;
+
+       // make sure fread fails
+       fd = dup(0);
+       close(0);
+
+       n = fread(buf, 1, sizeof buf, stdin);
+       if (n != 0 || !ferror(stdin))
+               t_error("fread(stdin) should have failed, got %d ferror %d feof %d\n",
+                       n, ferror(stdin), feof(stdin));
+       if (dup(fd) != 0)
+               t_error("dup failed\n");
+
+       rewind(stdin);
+       if (ferror(stdin))
+               t_error("rewind failed to clear ferror\n");
+       return t_status;
+}