~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to fpcdocs/bunixex/ex20.pp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Program Example20;
 
2
 
 
3
{ Program to demonstrate the fdRead and fdTruncate functions. }
 
4
 
 
5
Uses BaseUnix;
 
6
 
 
7
Const Data : string[10] = '1234567890';
 
8
 
 
9
Var FD : cint;
 
10
    l : longint;
 
11
 
 
12
begin
 
13
  FD:=fpOpen('test.dat',o_wronly or o_creat,&666);
 
14
  if fd>0 then
 
15
    begin
 
16
    { Fill file with data }
 
17
    for l:=1 to 10 do
 
18
      if fpWrite (FD,Data[1],10)<>10 then
 
19
        begin
 
20
        writeln ('Error when writing !');
 
21
        halt(1);
 
22
        end;
 
23
    fpClose(FD);
 
24
    FD:=fpOpen('test.dat',o_rdonly);
 
25
    { Read data again }
 
26
    If FD>0 then
 
27
      begin
 
28
      For l:=1 to 5 do
 
29
        if fpRead (FD,Data[1],10)<>10 then
 
30
          begin
 
31
          Writeln ('Error when Reading !');
 
32
          Halt(2);
 
33
          end;
 
34
      fpClose(FD);
 
35
      { Truncating file at 60 bytes }
 
36
      { For truncating, file must be open or write }
 
37
      FD:=fpOpen('test.dat',o_wronly,&666);
 
38
      if FD>0 then
 
39
        begin
 
40
        if fpfTruncate(FD,60)<>0 then
 
41
           Writeln('Error when truncating !');
 
42
        fpClose (FD);
 
43
        end;
 
44
      end;
 
45
    end;
 
46
end.