From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2644 invoked by alias); 10 Aug 2005 16:12:59 -0000 Mailing-List: contact glibc-bugs-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sources.redhat.com Received: (qmail 2626 invoked by uid 48); 10 Aug 2005 16:12:54 -0000 Date: Wed, 10 Aug 2005 16:12:00 -0000 From: "funtoos at yahoo dot com" To: glibc-bugs@sources.redhat.com Message-ID: <20050810161252.1190.funtoos@yahoo.com> Reply-To: sourceware-bugzilla@sources.redhat.com Subject: [Bug libc/1190] New: fgetc()/fread() behaviour is not POSIX compliant X-Bugzilla-Reason: CC X-SW-Source: 2005-08/txt/msg00054.txt.bz2 List-Id: A simple setup consisting of two programs. process A writes to fpA pointing to file /a/b/c and process B reads from fpB pointing to file /a/b/c. Process B does a select on fileno(fpB) for read readiness and does a fread() for 200 bytes. This leads to 256 bytes read and EOF. Process A writes more data to fpA. Process B again does a select(), followed by the fread(). (The select() calls don't wait for timeout=250 msecs that they are supposed to wait because eof is still set and select() rightly assumes that the fd is ready for read.) The second fread() succeeds when the data actually becomes available as written by process A. The second fread() should fail as per POSIX standard because the eof is still not cleared by the app and an fgetc() (used by fread()), returns eof if eof is set on the stream. This leads bad coding practices in linux and non-portable programs. The above is a live example of how non-portable the NX free client (called nxrun) became when app developer assumed that he could keep reading without resetting the eof on the stream. Not only the program hangs on solaris, but it sits in a tight loop because select() returns immediately on eof and the wait of 250 ms is rendered redundant, on both linux and solaris. If fgetc() and hence fread() had refused to read if stream has eof set like they are supposed as per POSIX, the programmer would have caught his mistake on linux and not led to hang on solaris and tight loop on linux. Please refer the following for correct POSIX behaviour of fgetc()/fread(): http://www.opengroup.org/onlinepubs/009695399/functions/fgetc.html http://www.opengroup.org/onlinepubs/009695399/functions/fread.html -- Summary: fgetc()/fread() behaviour is not POSIX compliant Product: glibc Version: unspecified Status: NEW Severity: critical Priority: P2 Component: libc AssignedTo: gotom at debian dot or dot jp ReportedBy: funtoos at yahoo dot com CC: glibc-bugs at sources dot redhat dot com GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://sources.redhat.com/bugzilla/show_bug.cgi?id=1190 ------- You are receiving this mail because: ------- You are on the CC list for the bug, or are watching someone who is.