[fpc-pascal] fpwrite buffers issues
ik
idokan at gmail.com
Mon Oct 8 09:52:25 CEST 2007
Hello List,
I'm trying to use fpwrite (from UnixBase). It seems that on my first
use it will wrtie the full content of the buffer, however on the
second write of the buffer, it will always write a small portion of
the buffer no matter the real size of it...
On an example that is written in C (that my code is based on), the
function always write the full content of the buffer to that device.
here is a small POC of my first attempt:
Const
BUFFER_LEN = 2048;
Buffer : array[0..BUFFER_LEN -1] of smallint;
My usage of fpwrite is as follows:
read_content := read_content_from....(... at Buffer[0], MAX_BUFFER);
while (read_content > 0) do
begin
write_count := fpwrite(fd, @Buffer[0], buffer_size * sizeof(buffertype));
read_content := read_content_from....(... at Buffer[0], MAX_BUFFER);
end;
Then I tried to do the following code, that continue to write the
buffer content until nothing more to write, but it reads wrong data:
start_count := 0;
output_count := readcount * sizeof(cshort);
read_content := read_content_from....(... at Buffer[0], MAX_BUFFER);
while (read_content > 0) do
begin
while (write_count > 0) do
begin
write_count := fpwrite (fd, @Buffer[start_count], output_count);
if (write_count > 0) then
begin
dec (output_count, write_count);
inc (start_count, write_count);
end ;
end;
read_content := read_content_from....(... at Buffer[0], MAX_BUFFER);
end;
I'm using ubuntu Linux amd64 using FPC 2.2.0
Any idea what I'm missing or doing wrong, and how to do it better ?
Thanks,
Ido
--
http://ik.homelinux.org/
More information about the fpc-pascal
mailing list