Subversion Repositories checksum-tools

Rev

Rev 3 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 6
Line 7... Line 7...
7
// by using the WinAPI (the "long filename" mode is switched when the file
7
// by using the WinAPI (the "long filename" mode is switched when the file
8
// name format \\?\ is used).
8
// name format \\?\ is used).
9
 
9
 
10
procedure MyAssignFile(var hFile: THandle; filename: string);
10
procedure MyAssignFile(var hFile: THandle; filename: string);
11
procedure MyReset(hFile: THandle);
11
procedure MyReset(hFile: THandle);
-
 
12
procedure MyRewrite(hFile: THandle);
-
 
13
procedure MyWriteLn(hFile: THandle; s: AnsiString);
12
procedure MyReadLn(hFile: THandle; var s: string);
14
procedure MyReadLn(hFile: THandle; var s: string);
13
procedure MyCloseFile(hFile: THandle);
15
procedure MyCloseFile(hFile: THandle);
14
function MyEOF(hFile: THandle): boolean;
16
function MyEOF(hFile: THandle): boolean;
15
procedure MyBlockRead(var hFile: THandle; var Buffer; RecordCount: integer; var RecordsRead: integer);
17
procedure MyBlockRead(var hFile: THandle; var Buffer; RecordCount: integer; var RecordsRead: integer);
16
 
18
 
Line 19... Line 21...
19
uses
21
uses
20
  Windows, SysUtils;
22
  Windows, SysUtils;
21
 
23
 
22
procedure MyAssignFile(var hFile: THandle; filename: string);
24
procedure MyAssignFile(var hFile: THandle; filename: string);
23
begin
25
begin
-
 
26
  hFile := CreateFile(PChar(filename), GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
-
 
27
  if hFile = INVALID_HANDLE_VALUE then
-
 
28
  begin
-
 
29
    if GetLastError = ERROR_ACCESS_DENIED then
-
 
30
    begin
24
  hFile := CreateFile(PChar(filename), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
31
      hFile := CreateFile(PChar(filename), GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, 0);
25
  if hFile = INVALID_HANDLE_VALUE then RaiseLastOSError;
32
      if hFile = INVALID_HANDLE_VALUE then RaiseLastOSError;
-
 
33
    end
-
 
34
    else RaiseLastOSError;
-
 
35
  end;
26
end;
36
end;
27
 
37
 
28
procedure MyReset(hFile: THandle);
38
procedure MyReset(hFile: THandle);
29
begin
39
begin
30
  SetFilePointer(hFile, 0, nil, FILE_BEGIN);
40
  SetFilePointer(hFile, 0, nil, FILE_BEGIN);
31
end;
41
end;
32
 
42
 
-
 
43
procedure MyRewrite(hFile: THandle);
-
 
44
begin
-
 
45
  SetFilePointer(hFile, 0, nil, FILE_BEGIN);
-
 
46
  SetEndOfFile(hFile);
-
 
47
end;
-
 
48
 
-
 
49
procedure MyWriteLn(hFile: THandle; s: AnsiString);
-
 
50
var
-
 
51
  numWritten: Cardinal;
-
 
52
begin
-
 
53
  s := s + #13#10;
-
 
54
  WriteFile(hFile, s[1], Length(s), numWritten, nil);
-
 
55
  if Cardinal(Length(s)) <> numWritten then RaiseLastOSError;
-
 
56
end;
-
 
57
 
33
procedure MyReadLn(hFile: THandle; var s: string);
58
procedure MyReadLn(hFile: THandle; var s: string);
34
var
59
var
35
  buf: array [0..0] of ansichar;
60
  buf: array [0..0] of ansichar;
36
  dwread: LongWord;
61
  dwread: LongWord;
37
begin
62
begin