The rawread procedure reads up to a specified number of characters from a file into a character buffer. The actual number of characters read by this procedure may be less than the maximum number of characters specified if there is an I/O error (you can check this by disabling I/O checking and using the getlasterror function) or if the end-of-file is reached.
The simple program below copies the contents of an input file into an output file. It is similar to the UNIX program "cat". The program uses the built-in procedures "rawread", and "rawwrite" to perform the I/O.
program cat(f, g);
const
max = 400;
var
f, g : text;
buffer : packed array[1..max] of char;
actual : integer;
begin
reset(f);
rewrite(g);
while not eof(f) do
begin
rawread(f, buffer, max, actual);
if actual <> 0 then
rawwrite(g, buffer, actual, actual);
end;
close(g);
close(f);
end.
Operating Systems: All
Standard Pascal: No