ex66.pp 672 B

123456789101112131415161718192021222324252627282930313233
  1. Program Example66;
  2. { Program to demonstrate the MMap function. }
  3. Uses BaseUnix,Unix;
  4. Var S : String;
  5. fd : cint;
  6. Len : longint;
  7. // args : tmmapargs;
  8. P : PChar;
  9. begin
  10. s:='This is the string';
  11. Len:=Length(S);
  12. fd:=fpOpen('testfile.txt',O_wrOnly or o_creat);
  13. If fd=-1 then
  14. Halt(1);
  15. If fpWrite(fd,S[1],Len)=-1 then
  16. Halt(2);
  17. fpClose(fd);
  18. fd:=fpOpen('testfile.txt',O_rdOnly);
  19. if fd=-1 then
  20. Halt(3);
  21. P:=Pchar(fpmmap(nil,len+1 ,PROT_READ or PROT_WRITE,MAP_PRIVATE,fd,0));
  22. If longint(P)=-1 then
  23. Halt(4);
  24. Writeln('Read in memory :',P);
  25. fpclose(fd);
  26. if fpMUnMap(P,Len)<>0 Then
  27. Halt(fpgeterrno);
  28. end.