* implemented recommendations from mantis #038510 for better bionic

compatibility.

git-svn-id: trunk@49167 -
This commit is contained in:
marco 2021-04-10 14:58:53 +00:00
parent 763d287af4
commit b2afecdae5

View File

@ -14,7 +14,7 @@ var
iconvres: size_t;
begin
H := iconv_open(PChar(ToEncoding), PChar(FromEncoding));
if not assigned(H) then
if h=Iconv_t(-1) then
begin
Res := S;
exit(-1);
@ -48,7 +48,8 @@ begin
Dst:=PChar(Res)+Offset;
OutLen:=Length(Res)-Offset;
end;
iconvres:=iconv(H, nil, nil, @Dst, @Outlen);
InLen=0;
iconvres:=iconv(H, nil, @InLen, @Dst, @Outlen);
if iconvres = size_t(-1) then
begin
res:=s;
@ -91,7 +92,8 @@ begin
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
Dst:=PChar(Res)+Offset;
OutLen:=Length(Res)-Offset;
iconv(H, nil, nil, @Dst, @Outlen);
InLen:=0;
iconv(H, nil, @InLen, @Dst, @Outlen);
end;
{$endif}
// trim output buffer
@ -101,7 +103,8 @@ begin
SetLength(Res, Length(Res)+InLen*2+5); // 5 is minimally one utf-8 char
Dst:=PChar(Res)+Offset;
OutLen:=Length(Res)-Offset;
iconvres:=iconv(H, nil, nil, @Dst, @Outlen);
InLen:=0;
iconvres:=iconv(H, nil, @InLen, @Dst, @Outlen);
setlength(Res,Length(Res) - Outlen);
iconv_close(H);
end;