UNIX Free Pascal


. - 3


readln(s1);

{$I-}

(* *)

if not access(pchar(s1),f_ok or r_ok) then

begin

writeln(' '+pchar(s1)+' ');

halt(1);

end;

writeln(' ');

readln(s2);

(* *)

t1:=fdopen(s1,Open_RDONLY);

w:=fdseek(t1,0,SEEK_END); (* *)

(* mmap*)

m.address:=0; (**)

m.offset:=0; (* *)

m.size:=w; (* *)

m.flags:=MAP_SHARED; (* *)

m.prot:=PROT_READ; (* *)

m.fd:=t1; (* *)

p1:=psmth(mmap(m)); (* , *)

if longint(p1)=-1 then

begin

writeln(' mmap (t1)');

fdclose(t1);

halt(0);

end;

(* , *)

t2:=fdopen(s2,Open_WRONLY or Open_TRUNC or Open_CREAT, octal(640));

if t2=-1 then

begin

writeln(' ',s2,' ');

halt(1);

end;

fdseek(t2,w-1,SEEK_SET);(* w-1 *)

fdwrite(t2,w,1); (*... 1 *)

fdclose(t2);

t2:=fdopen(s2,Open_RDWR);(* *)

m.address:=0;

m.offset:=0;

m.size:=w;

m.flags:=MAP_SHARED;

m.prot:=PROT_WRITE or PROT_READ;

m.fd:=t2;

p2:=psmth(mmap(m));

if longint(p2)=-1 then

begin

writeln(' mmap (t2)');

fdclose(t1);

fdclose(t2);

munmap(p1,w);

halt(0);

end;

(* *)

for n:=0 to w-1 do

p2^[n]:=p1^[n];

(* *)

munmap(p1,w);

munmap(p2,w);

fdclose(t1);

fdclose(t2);

writeln(' ',s1,' ',s2);

END.

 




- -  - -  - -