ex20.pp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. Program Example20;
  2. { Program to demonstrate the fdRead and fdTruncate functions. }
  3. Uses linux;
  4. Const Data : string[10] = '12345687890';
  5. Var FD : Longint;
  6. l : longint;
  7. begin
  8. FD:=fdOpen('test.dat',open_wronly or open_creat,octal(666));
  9. if fd>0 then
  10. begin
  11. { Fill file with data }
  12. for l:=1 to 10 do
  13. if fdWrite (FD,Data[1],10)<>10 then
  14. begin
  15. writeln ('Error when writing !');
  16. halt(1);
  17. end;
  18. fdClose(FD);
  19. FD:=fdOpen('test.dat',open_rdonly);
  20. { Read data again }
  21. If FD>0 then
  22. begin
  23. For l:=1 to 5 do
  24. if fdRead (FD,Data[1],10)<>10 then
  25. begin
  26. Writeln ('Error when Reading !');
  27. Halt(2);
  28. end;
  29. fdCLose(FD);
  30. { Truncating file at 60 bytes }
  31. { For truncating, file must be open or write }
  32. FD:=fdOpen('test.dat',open_wronly,octal(666));
  33. if FD>0 then
  34. begin
  35. if not fdTruncate(FD,60) then
  36. Writeln('Error when truncating !');
  37. fdClose (FD);
  38. end;
  39. end;
  40. end;
  41. end.