mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-27 17:19:14 +02:00
* Windows targets: removed 'errno' threadvar, OS error codes can be passed directly to Errno2InOutRes().
git-svn-id: trunk@26815 -
This commit is contained in:
parent
d91da3bd6b
commit
c83f4c5ddc
@ -30,10 +30,10 @@ begin
|
||||
DoDirSeparators(s);
|
||||
if not aFunc(punicodechar(s)) then
|
||||
begin
|
||||
errno:=GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
end;
|
||||
|
||||
Procedure do_MkDir(const s: UnicodeString);
|
||||
begin
|
||||
dirfn(TDirFnType(@CreateDirectoryTrunc),s);
|
||||
@ -123,8 +123,7 @@ begin
|
||||
Len2 := GetFullPathNameW (@Drive, Len, PUnicodeChar (Dir), P);
|
||||
if Len2 = 0 then
|
||||
begin
|
||||
errno := word (GetLastError);
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
Dir := widechar (DriveNr + Ord ('A') - 1) + ':\';
|
||||
Exit;
|
||||
end
|
||||
|
@ -35,18 +35,19 @@ end;
|
||||
procedure do_erase(p: pwidechar; pchangeable: boolean);
|
||||
var
|
||||
oldp: pwidechar;
|
||||
err: longword;
|
||||
begin
|
||||
oldp:=p;
|
||||
DoDirSeparators(p,pchangeable);
|
||||
if DeleteFileW(p)=0 then
|
||||
Begin
|
||||
errno:=GetLastError;
|
||||
if errno=5 then
|
||||
err:=GetLastError;
|
||||
if err=5 then
|
||||
begin
|
||||
if ((GetFileAttributesW(p) and FILE_ATTRIBUTE_DIRECTORY)=FILE_ATTRIBUTE_DIRECTORY) then
|
||||
errno:=2;
|
||||
err:=2;
|
||||
end;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(err);
|
||||
end;
|
||||
if p<>oldp then
|
||||
freemem(p);
|
||||
@ -62,10 +63,9 @@ begin
|
||||
DoDirSeparators(p1,p1changeable);
|
||||
DoDirSeparators(p2,p2changeable);
|
||||
if MoveFileW(p1,p2)=0 then
|
||||
Begin
|
||||
errno:=GetLastError;
|
||||
Errno2InoutRes;
|
||||
end;
|
||||
Begin
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
if p1<>oldp1 then
|
||||
freemem(p1);
|
||||
if p2<>oldp2 then
|
||||
@ -84,8 +84,7 @@ var
|
||||
begin
|
||||
if writefile(h,addr,len,size,nil)=0 then
|
||||
Begin
|
||||
errno:=GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
{$ifndef WINCE}
|
||||
end
|
||||
else if (size<len) then
|
||||
@ -120,14 +119,13 @@ end;
|
||||
function do_read(h:thandle;addr:pointer;len : longint) : longint;
|
||||
var
|
||||
_result:longint;
|
||||
err: longword;
|
||||
begin
|
||||
if readfile(h,addr,len,_result,nil)=0 then
|
||||
Begin
|
||||
errno:=GetLastError;
|
||||
if errno=ERROR_BROKEN_PIPE then
|
||||
errno:=0
|
||||
else
|
||||
Errno2InoutRes;
|
||||
err:=GetLastError;
|
||||
if err<>ERROR_BROKEN_PIPE then
|
||||
Errno2InoutRes(err);
|
||||
end;
|
||||
do_read:=_result;
|
||||
end;
|
||||
@ -146,8 +144,7 @@ begin
|
||||
rslt.low := SetFilePointer(handle, 0, @rslt.high, FILE_CURRENT);
|
||||
if (rslt.low = $FFFFFFFF) and (GetLastError <> 0) then
|
||||
begin
|
||||
errno := GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
do_filepos := int64(rslt);
|
||||
end;
|
||||
@ -162,8 +159,7 @@ begin
|
||||
{ return value of -1 is valid unless GetLastError is non-zero }
|
||||
(GetLastError <> 0) then
|
||||
begin
|
||||
errno := GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -176,8 +172,7 @@ begin
|
||||
rslt.low := SetFilePointer(handle, 0, @rslt.high, FILE_END);
|
||||
if (rslt.low = $FFFFFFFF) and (GetLastError <> 0) then
|
||||
begin
|
||||
errno := GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
do_seekend := int64(rslt);
|
||||
end;
|
||||
@ -198,8 +193,7 @@ begin
|
||||
do_seek(handle,pos);
|
||||
if not(SetEndOfFile(handle)) then
|
||||
begin
|
||||
errno:=GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -317,8 +311,7 @@ begin
|
||||
{ handle -1 is returned sometimes !! (PM) }
|
||||
if (filerec(f).handle=0) or (filerec(f).handle=UnusedHandle) then
|
||||
begin
|
||||
errno:=GetLastError;
|
||||
Errno2InoutRes;
|
||||
Errno2InoutRes(GetLastError);
|
||||
end;
|
||||
if oldp<>p then
|
||||
freemem(p);
|
||||
|
@ -192,10 +192,6 @@ type
|
||||
end;
|
||||
|
||||
|
||||
threadvar
|
||||
errno : longint;
|
||||
|
||||
|
||||
{ misc. functions }
|
||||
function GetLastError : DWORD;
|
||||
{$ifdef wince}cdecl{$else}stdcall{$endif};external KernelDLL name 'GetLastError';
|
||||
@ -323,19 +319,17 @@ threadvar
|
||||
len:dword): Integer; stdcall;external 'oleaut32.dll' name 'SysReAllocStringLen';
|
||||
{$endif WINCE}
|
||||
|
||||
Procedure Errno2InOutRes;
|
||||
Procedure Errno2InOutRes(oserror: longword);
|
||||
var
|
||||
res : Word;
|
||||
pErrno : ^longint;
|
||||
Begin
|
||||
{ DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
|
||||
pErrno:=@Errno;
|
||||
case pErrno^ of
|
||||
case oserror of
|
||||
ERROR_WRITE_PROTECT..ERROR_GEN_FAILURE :
|
||||
begin
|
||||
{ This is the offset to the Win32 to add to directly map }
|
||||
{ to the DOS/TP compatible error codes when in this range }
|
||||
res := word(pErrno^)+131;
|
||||
res := word(oserror)+131;
|
||||
end;
|
||||
ERROR_DISK_FULL :
|
||||
res := 101;
|
||||
@ -348,10 +342,9 @@ threadvar
|
||||
else
|
||||
begin
|
||||
{ other error codes can directly be mapped }
|
||||
res := Word(pErrno^);
|
||||
res := Word(oserror);
|
||||
end;
|
||||
end;
|
||||
pErrno^:=0;
|
||||
InOutRes:=res;
|
||||
end;
|
||||
|
||||
|
@ -683,8 +683,6 @@ begin
|
||||
{ Reset IO Error }
|
||||
InOutRes:=0;
|
||||
ProcessID := GetCurrentProcessID;
|
||||
{ Reset internal error variable }
|
||||
errno:=0;
|
||||
initvariantmanager;
|
||||
DispCallByIDProc:=@DoDispCallByIDError;
|
||||
end.
|
||||
|
@ -615,8 +615,6 @@ begin
|
||||
{ Reset IO Error }
|
||||
InOutRes:=0;
|
||||
ProcessID := GetCurrentProcessID;
|
||||
{ Reset internal error variable }
|
||||
errno:=0;
|
||||
initvariantmanager;
|
||||
DispCallByIDProc:=@DoDispCallByIDError;
|
||||
end.
|
||||
|
@ -1783,8 +1783,6 @@ initialization
|
||||
ProcessID := GetCurrentProcessID;
|
||||
{ threading }
|
||||
InitSystemThreads;
|
||||
{ Reset internal error variable }
|
||||
errno:=0;
|
||||
initvariantmanager;
|
||||
DispCallByIDProc:=@DoDispCallByIDError;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user