C (75/207)

From:David Arbuthnot
Date:10 Dec 99 at 15:23:56
Subject:FRead()/FWrite()

From: David Arbuthnot <Trebor@Digital.Prestel.co.uk>

Hello,

I'm writing a copy routine and I would like to use FRead()/FWrite()
however this is not possible as they don't return the number of
bytes read but the number of blocks. The core of my routine looks
like this:

<SNIP>

while(br = Read(fileSrc,dataBuffer,nibblesize))
{
Write(fileDst,dataBuffer,br);
}

<SNIP>

the above fragment of my routine works like a dream but using FRead/FWrite
does not (I need to use buffered calls as the rest of my program is using
buffered calls and you have to flush the buffer between Read/FRead &
Write/FWrite calls. My routine does a nibble copy (In future I'm hoping to
add some sort of verification process to test the data while the file is
being copied) by reading an amount of bytes and the writing them.

I did try the following:

<SNIP>

while(br = FRead(fileSrc,dataBuffer,nibblesize,1))
{
FWrite(fileDst,dataBuffer,br*nibblesize,1);
}

<SNIP>

but this won't work because if fread does not read a full block I have
no easy way to find out how many bytes FRead actually read (unless I counted
the buffer i store the data in, but this provides the problem of what
character to use as meaning that there is no more data, i.e I can't test
for 0x00 as the file being copied could be a binary file that contains
0x00's)

I can't seem to find a way around this problem.

Regards

Dave `Trebor' Arbuthnot