The rawread procedure

Description

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.

Parameter

  1. The first parameter is a reference to the file variable associated with the file to read.
  2. The second parameter is a reference to the character buffer used to store the characers read from the file. The character buffer must be a variable of type string or a packed array of type char.
  3. The third parameter is an expression of integral type which specifies the maximum number of characters to read from the file.
  4. The fourth parameter is a reference to a variable of type integer or type word which will contain the actual number of characters read from the file.

Example

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.

Portability

Operating Systems: All
Standard Pascal: No