From owner-freebsd-questions Tue Aug 27 18:11: 3 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 274B937B410 for ; Tue, 27 Aug 2002 18:11:01 -0700 (PDT) Received: from ns.itga.com.au (ns.itga.com.au [202.53.40.210]) by mx1.FreeBSD.org (Postfix) with ESMTP id C78E643E77 for ; Tue, 27 Aug 2002 18:10:59 -0700 (PDT) (envelope-from gnb@itga.com.au) Received: from lightning.itga.com.au (lightning.itga.com.au [192.168.71.20]) by ns.itga.com.au (8.9.3/8.9.3) with ESMTP id LAA35234; Wed, 28 Aug 2002 11:10:57 +1000 (EST) (envelope-from gnb@itga.com.au) Received: from lightning.itga.com.au (localhost [127.0.0.1]) by lightning.itga.com.au (8.9.3/8.9.3) with ESMTP id LAA01291; Wed, 28 Aug 2002 11:10:56 +1000 (EST) Message-Id: <200208280110.LAA01291@lightning.itga.com.au> X-Mailer: exmh version 2.4 05/15/2001 with nmh-1.0.4 From: Gregory Bond To: ERIK G HAMILTON Cc: freebsd-questions@FreeBSD.ORG Subject: Re: fread returns eof too soon on a binary file In-reply-to: Your message of Tue, 27 Aug 2002 03:19:36 -0500. Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Wed, 28 Aug 2002 11:10:56 +1000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG [This is not an appropriate topic for freebsd-bugs] The hole you are missing is: What if send() returns a count less than len but greater than 0? You send only part of a block, but then go and fread() more data from the current file offset, so the bit in the current block that send() didn't transmit never gets sent. And what if fread() returns less than len bytes? You'll wind up sending more data than you've read. This is nothing to do with fread(), you have two glaring errors in handling byte counts and short reads/writes. Have a look at any Unix programming book which should cover this stuff. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message