From owner-freebsd-questions Tue Aug 27 20: 4:38 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 C398937B400 for ; Tue, 27 Aug 2002 20:04:35 -0700 (PDT) Received: from dc-mx12.cluster1.charter.net (dc-mx12.cluster1.charter.net [209.225.8.22]) by mx1.FreeBSD.org (Postfix) with ESMTP id 287BA43E42 for ; Tue, 27 Aug 2002 20:04:35 -0700 (PDT) (envelope-from ehamilt@siue.edu) Received: from [24.171.35.20] (HELO amd800) by dc-mx12.cluster1.charter.net (CommuniGate Pro SMTP 3.5.9) with SMTP id 71137786; Tue, 27 Aug 2002 23:03:24 -0400 Message-ID: <008701c24e3f$fa46b800$0200000a@amd800> From: "Erik" To: "Gregory Bond" Cc: References: <200208280110.LAA01291@lightning.itga.com.au> Subject: Re: fread returns eof too soon on a binary file Date: Tue, 27 Aug 2002 22:06:58 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 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 I'll bite. What book is that? Although who needs books when you can screw up and ask a mailing list? Erik ----- Original Message ----- From: "Gregory Bond" To: "ERIK G HAMILTON" Cc: Sent: Tuesday, August 27, 2002 8:10 PM Subject: Re: fread returns eof too soon on a binary file > [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