Back to index

glibc  2.9
tst-ferror.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 
00003 int
00004 main (int argc, char *argv[])
00005 {
00006   char buf[100];
00007   int result = 0;
00008 
00009   if (ferror (stdin) != 0)
00010     {
00011       fputs ("error bit set for stdin at startup\n", stdout);
00012       result = 1;
00013     }
00014   if (fgets (buf, sizeof buf, stdin) != buf)
00015     {
00016       fputs ("fgets with existing input has problem\n", stdout);
00017       result = 1;
00018     }
00019   if (ferror (stdin) != 0)
00020     {
00021       fputs ("error bit set for stdin after setup\n", stdout);
00022       result = 1;
00023     }
00024   if (fputc ('a', stdin) != EOF)
00025     {
00026       fputs ("fputc to stdin does not terminate with an error\n", stdout);
00027       result = 1;
00028     }
00029   if (ferror (stdin) == 0)
00030     {
00031       fputs ("error bit not set for stdin after fputc\n", stdout);
00032       result = 1;
00033     }
00034   clearerr (stdin);
00035   if (ferror (stdin) != 0)
00036     {
00037       fputs ("error bit set for stdin after clearerr\n", stdout);
00038       result = 1;
00039     }
00040   return result;
00041 }