[Overview][Constants][Types][Procedures and functions][Variables][Index] Reference for unit 'oldlinux' (#rtl)

fdRead

Read data from file descriptor

Declaration

Source position: oldlinux.pp line 1384

function fdRead(

  fd: LongInt;

  var buf;

  size: LongInt

):LongInt;

Description

fdRead reads at most size bytes from the file descriptor fd, and stores them in buf. The function returns the number of bytes actually read, or -1 if an error occurred. No checking on the length of buf is done.

Errors

Errors are returned in LinuxError.

See also

fdOpen

  

Open file and return file descriptor

fdClose

  

Close file descriptor

fdWrite

  

Write data to file descriptor

fdTruncate

  

Truncate file on certain size.

fdFlush

  

Flush kernel file buffer

fdSeek

  

Set file pointer position.

Example

Program Example20;

{ Program to demonstrate the fdRead and fdTruncate functions. }

Uses oldlinux;

Const Data : string[10] = '12345687890';

Var FD : Longint;
    l : longint;

begin
  FD:=fdOpen('test.dat',open_wronly or open_creat,octal(666));
  if fd>0 then
    begin
    { Fill file with data }
    for l:=1 to 10 do
      if fdWrite (FD,Data[1],10)<>10 then
        begin
        writeln ('Error when writing !');
        halt(1);
        end;
    fdClose(FD);
    FD:=fdOpen('test.dat',open_rdonly);
    { Read data again }
    If FD>0 then
      begin
      For l:=1 to 5 do
        if fdRead (FD,Data[1],10)<>10 then
          begin
          Writeln ('Error when Reading !');
          Halt(2);
          end;
      fdCLose(FD);
      { Truncating file at 60 bytes }
      { For truncating, file must be open or write }
      FD:=fdOpen('test.dat',open_wronly,octal(666));
      if FD>0 then
        begin
        if not fdTruncate(FD,60) then
           Writeln('Error when truncating !');
        fdClose (FD);
        end;
      end;
    end;
end.
The latest version of this document can be found at lazarus-ccr.sourceforge.net.