Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Aug 2002 11:10:56 +1000
From:      Gregory Bond <gnb@itga.com.au>
To:        ERIK G HAMILTON <ehamilt@siue.edu>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: fread returns eof too soon on a binary file 
Message-ID:  <200208280110.LAA01291@lightning.itga.com.au>
In-Reply-To: Your message of Tue, 27 Aug 2002 03:19:36 -0500.

next in thread | raw e-mail | index | archive | help
[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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200208280110.LAA01291>