[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fflush does not detect error case when operating on stdin
From: |
Bernard WEISSER |
Subject: |
fflush does not detect error case when operating on stdin |
Date: |
Mon, 07 Feb 2005 22:12:09 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040618 |
Hello,
I found a code that tried to fflush on stdin and that returned a 0
status but a non-nul errno value.
My configuration is :
Linux mars 2.4.26 #6 Mon Jun 14 19:07:27 PDT 2004 i686
>Release: libc-2.3.2
>Environment:
<machine, os, target, libraries (multiple lines)>
Host type: i486-slackware-linux-gnu
System: Linux mars 2.4.26 #6 Mon Jun 14 19:07:27 PDT 2004 i686 unknown
unknown GNU/Linux
Architecture: i686
Addons: linuxthreads
Build CFLAGS: -g -O2 -march=i486 -mcpu=i686
Build CC: i486-slackware-linux-gcc
Compiler version: 3.3.3
Kernel headers: 2.4.26
Symbol versioning: yes
Build static: yes
Build shared: yes
Build pic-default: no
Build profile: yes
Build omitfp: no
Build bounded: no
Build static-nss: no
Here is the code :
/*
* Execution gives the following output :
*
* Enter an integer, then a CR : 123
* errno = 0
* flushing stdin...
* fflush OK <============= should not be OK
* errno = Illegal seek
*
* When flusing the non-empty stdin, fflush does not return -1, but 0.
* -1 was expected, since fflush should be applied only to an output stream.
* An error situation should have occured, since errno is also set to
* indicate an "Illegal seek" error.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (void)
{
int i, status ;
printf ("Enter an integer, then a CR : ") ;
if (scanf ("%d", &i) != 1) {
printf ("scanf error\n") ;
exit (1) ;
}
printf ("errno = %d\n", errno) ;
printf ("flushing stdin...\n") ;
status = fflush (stdin) ;
if (status != 0) {
printf ("fflush error\n") ;
}
else {
printf ("fflush OK\n") ;
}
if (errno == -1) {
perror ("fflush") ;
}
else {
printf ("errno = %s\n", strerror (errno)) ;
}
return 0 ;
}
Do you think this is a bug ?
- fflush does not detect error case when operating on stdin,
Bernard WEISSER <=