• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // commit: a6238c30d169cbac6bc4c4977622242063e32270 2011-02-22
2 // rewind should clear error
3 #include <stdio.h>
4 #include <unistd.h>
5 #include "test.h"
6 
main(void)7 int main(void)
8 {
9 	char buf[1];
10 	size_t n;
11 	int fd;
12 
13 	// make sure fread fails
14 	fd = dup(0);
15 	close(0);
16 
17 	n = fread(buf, 1, sizeof buf, stdin);
18 	if (n != 0 || !ferror(stdin))
19 		t_error("fread(stdin) should have failed, got %d ferror %d feof %d\n",
20 			n, ferror(stdin), feof(stdin));
21 	if (dup(fd) != 0)
22 		t_error("dup failed\n");
23 
24 	rewind(stdin);
25 	if (ferror(stdin))
26 		t_error("rewind failed to clear ferror\n");
27 	return t_status;
28 }
29