Contents | Prev | Next

7.4.43 The rawwrite procedure

Description

The rawwrite procedure writes up to a specified number of characters from a character buffer to a file. The actual number of characters written 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).

Parameter

  1. The first parameter is a reference to the file variable associated with the file to write.
  2. The second parameter is a reference to the character buffer used to store the characers to be written to 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 be written to 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 written to 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

Contents | Prev | Next