1570af302Sopenharmony_ci// commit: a6238c30d169cbac6bc4c4977622242063e32270 2011-02-22 2570af302Sopenharmony_ci// rewind should clear error 3570af302Sopenharmony_ci#include <stdio.h> 4570af302Sopenharmony_ci#include <unistd.h> 5570af302Sopenharmony_ci#include "test.h" 6570af302Sopenharmony_ci 7570af302Sopenharmony_ciint main(void) 8570af302Sopenharmony_ci{ 9570af302Sopenharmony_ci char buf[1]; 10570af302Sopenharmony_ci size_t n; 11570af302Sopenharmony_ci int fd; 12570af302Sopenharmony_ci 13570af302Sopenharmony_ci // make sure fread fails 14570af302Sopenharmony_ci fd = dup(0); 15570af302Sopenharmony_ci close(0); 16570af302Sopenharmony_ci 17570af302Sopenharmony_ci n = fread(buf, 1, sizeof buf, stdin); 18570af302Sopenharmony_ci if (n != 0 || !ferror(stdin)) 19570af302Sopenharmony_ci t_error("fread(stdin) should have failed, got %d ferror %d feof %d\n", 20570af302Sopenharmony_ci n, ferror(stdin), feof(stdin)); 21570af302Sopenharmony_ci if (dup(fd) != 0) 22570af302Sopenharmony_ci t_error("dup failed\n"); 23570af302Sopenharmony_ci 24570af302Sopenharmony_ci rewind(stdin); 25570af302Sopenharmony_ci if (ferror(stdin)) 26570af302Sopenharmony_ci t_error("rewind failed to clear ferror\n"); 27570af302Sopenharmony_ci return t_status; 28570af302Sopenharmony_ci} 29