On Fri, 3 Jan 2014, Dennis Poon wrote:



Michael Van Canneyt wrote:


On Thu, 5 Dec 2013, Dennis Poon wrote:

I tried to read the mac address in the captioned file path.
In terminal, I can simply 'cat' and display the mac address.

In FPC, when I tried to use TFileStream to read it,

FS := TFileStream.Create('/sys/class/net/eth1/address', fmOpenRead+fmShareDenyWrite);

it raised "stream read error"

The problem is not there.

{//strange, the following will raise stream read error
       FS := TFilestream.Create(FileName, fmOpenRead+fmShareDenyWrite );
       try
         if FS.Size > 0 then begin
           SetLength(s, FS.Size);
           FS.ReadBuffer(s[1], FS.Size);

This is the source of your problem. ReadBuffer raises an error if LESS THAN FS.Size bytes have been read.

The size *reported* by the linux kernel is 4K, but actually read bytes is only 
16 or so.

So, just change this line to
SetLength(S,FS.Read(s[1], FS.Size));

And all will be well. I tested.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to