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

Dup

Duplicate a file handle

Declaration

Source position: line 0

function Dup(

  oldfile: LongInt;

  var newfile: LongInt

):Boolean;

function Dup(

  var oldfile: text;

  var newfile: text

):Boolean;

function Dup(

  var oldfile: ;

  var newfile:

):Boolean;

Description

Makes NewFilean exact copy of OldFile, after having flushed the buffer of OldFilein case it is a Text file or untyped file. Due to the buffering mechanism of Pascal, this has not the same functionality as the dup call in C. The internal Pascal buffers are not the same after this call, but when the buffers are flushed (e.g. after output), the output is sent to the same file. Doing an lseek will, however, work as in C, i.e. doing a lseek will change the fileposition in both files.

The function returns Falsein case of an error, Trueif successful.

Errors

In case of errors, Linuxerroris used to report errors.

sys_ebadf
OldFilehasn't been assigned.
sys_emfile
Maximum number of open files for the process is reached.

See also

Dup2

  

Duplicate one filehandle to another

Example

program Example31;

{ Program to demonstrate the Dup function. }

uses oldlinux;

var f : text;

begin
  if not dup (output,f) then
    Writeln ('Dup Failed !');
  writeln ('This is written to stdout.');
  writeln (f,'This is written to the dup file, and flushed');flush(f);
  writeln
end.