summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw13536.pp
blob: a3cb9d5315da631bb564129dae6527bbd7f1299d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87

// without -O3 prints  0002020200010101
// with -O3 prints 0001010100010101

{$mode objfpc}{$H+}

uses sysutils;

Const
   MAXDWORD = $FFFFFFFF;


Type
 Filetime=longint;
 tchar=char;
 XWIN32_FIND_DATA = record
          dwFileAttributes : DWORD;
          ftLastWriteTime : FILETIME;
          nFileSizeHigh : DWORD;
          nFileSizeLow : DWORD;
          cFileName : array[0..(MAX_PATH)-1] of TCHAR;
       end;

Type
  TMySearchRec = Record
    Time : Longint;
    Size : Int64;
    Attr : Longint;
    Name : TFileName;
    ExcludeAttr : Longint;
    FindHandle : THandle;
    FindData : XWIN32_FIND_DATA;
  end;

function getlasterror:integer;
begin
end;

function aFindNextFile (F:thandle;fd:XWIN32_FIND_DATA):boolean;
begin

end;

function WinToDosTime( Var Wtime : FileTime;var DTime:longint):longbool;
begin
end;

Function aFindMatch(var f: TMySearchRec) : Longint;
begin
  // commenting code before the f.size:= line seems to alter the behaviour
  { Find file with correct attribute }
  While (F.FindData.dwFileAttributes and cardinal(F.ExcludeAttr))<>0 do
   begin
     if not aFindNextFile (F.FindHandle,F.FindData) then
      begin
        Result:=GetLastError;
        exit;
      end;
   end; 

  { Convert some attributes back }
  WinToDosTime(F.FindData.ftLastWriteTime,F.Time);

  f.size:=F.FindData.NFileSizeLow+(qword(maxdword)+1)*F.FindData.NFileSizeHigh;
  f.attr:=F.FindData.dwFileAttributes;
  f.Name:=StrPas(@F.FindData.cFileName[0]);
  Result:=0;
end;

var n : TMySearchRec;

begin 
 // make sure it gets past the while loop.
 n.finddata.dwfileattributes:=1;
 n.excludeattr:=0;

 n.FindData.NFileSizeLow:=$10101;
 n.FindData.NFileSizehigh:=$20202;
 // attempt to avoid problems with strpas.
 n.finddata.cfilename:='bla'#0;
 aFindMatch(n);

 writeln(n.size);
 writeln(inttohex(n.size,16));
 if (n.size<>$0002020200010101) then
   halt(1);
end.