~ubuntu-branches/ubuntu/dapper/fpc/dapper

« back to all changes in this revision

Viewing changes to docs/linuxex/ex66.pp

  • Committer: Bazaar Package Importer
  • Author(s): Carlos Laviola
  • Date: 2004-08-12 16:29:37 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20040812162937-moo8ulvysp1ln771
Tags: 1.9.4-5
fp-compiler: needs ld, adding dependency on binutils.  (Closes: #265265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
{ Program to demonstrate the MMap function. }
4
4
 
5
 
Uses linux;
 
5
Uses BaseUnix,Unix;
6
6
 
7
 
Var S : String;
8
 
    fd,Len : Longint;
9
 
    args : tmmapargs;
10
 
    P : PChar;
 
7
Var S    : String;
 
8
    fd   : cint;
 
9
    Len  : longint;
 
10
//    args : tmmapargs;
 
11
    P    : PChar;
11
12
        
12
13
begin
13
 
  S:='This is a string'#0;
 
14
  s:='This is the string';
14
15
  Len:=Length(S);
15
 
  fd:=fdOpen('testfile.txt',Open_wrOnly or open_creat);
 
16
  fd:=fpOpen('testfile.txt',O_wrOnly or o_creat);
16
17
  If fd=-1 then 
17
18
    Halt(1);
18
 
  If fdWrite(fd,S[1],Len)=-1 then
 
19
  If fpWrite(fd,S[1],Len)=-1 then
19
20
    Halt(2);
20
 
  fdClose(fd);
21
 
  fdOpen('testfile.txt',Open_rdOnly);
 
21
  fpClose(fd);
 
22
  fd:=fpOpen('testfile.txt',O_rdOnly);
22
23
  if fd=-1 then
23
24
    Halt(3);
24
 
  args.address:=0;
25
 
  args.offset:=0;
26
 
  args.size:=Len+1;
27
 
  args.fd:=Fd;
28
 
  args.flags:=MAP_PRIVATE;
29
 
  args.prot:=PROT_READ or PROT_WRITE;
30
 
  P:=Pchar(mmap(args));
 
25
  P:=Pchar(fpmmap(nil,len+1 ,PROT_READ or PROT_WRITE,MAP_PRIVATE,fd,0));
 
26
 
31
27
  If longint(P)=-1 then
32
28
    Halt(4);
33
29
  Writeln('Read in memory  :',P);
34
 
  fdclose(fd);
35
 
  if Not MUnMap(P,Len) Then
36
 
    Halt(LinuxError);
 
30
  fpclose(fd);
 
31
  if fpMUnMap(P,Len)<>0 Then
 
32
    Halt(fpgeterrno);
37
33
end.