From 1c828670f3a5cffc32bf527ecac846161711ee45 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Mon, 16 Jun 2008 22:33:31 +0200 Subject: PPC (32bit) fixes --- UCoreUtils.pas | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'UCoreUtils.pas') diff --git a/UCoreUtils.pas b/UCoreUtils.pas index 0bccb8b..93bbff0 100644 --- a/UCoreUtils.pas +++ b/UCoreUtils.pas @@ -195,13 +195,14 @@ begin if f < 0 then f := ConfSizeFormat; case f of 0 : begin // System default formatting - p := malloc(255); - memset(p, 0, 255); - if sprintf(p, '%''lu', Value div Base) < 1 then begin + p := g_strdup_printf('%''lu', Int64(Value div Base)); + if p = nil then begin DebugMsg(['FormatSize(0): sprintf() failed, using old format function.']); Result := FormatFloat('###,###,##0', Value div Base); - end else Result := StrToUTF8(p); - free(p); + end else begin + Result := StrToUTF8(p); + g_free(p); + end; end; 1 : begin // 123456 Result := IntToStr(Value div Base); @@ -308,7 +309,7 @@ begin placed := strftime(Buf, 254, PChar(DateFormat), time_tm); if placed <= 0 then DebugMsg(['FormatDate: error converting date. The result will be unpredictable.']); DateString := String(StrToUTF8(Buf)); - free(Buf); + libc_free(Buf); end; if FormatTime then begin @@ -332,7 +333,7 @@ begin placed := strftime(Buf, 254, PChar(TimeFormat), time_tm); if placed <= 0 then DebugMsg(['FormatDate: error converting time. The result will be unpredictable.']); TimeString := String(StrToUTF8(Buf)); - free(Buf); + libc_free(Buf); end; if FormatDate and FormatTime then begin @@ -1481,11 +1482,11 @@ end; function StrToUTF8(s: PChar): PChar; var bytes_read, bytes_written: gsize; error: PGError; - ns: PChar; + ns, nss: PChar; m: PChar; begin if g_utf8_validate(s, strlen(s), nil) then begin - Result := g_strndup(s, strlen(s)); + Result := strndup(s, strlen(s)); Exit; end; // DebugMsg(['StrToUTF8: string "', s, '" is not valid UTF-8.']); @@ -1502,9 +1503,11 @@ begin g_error_free(error); end; if @g_filename_display_name <> nil then begin - Result := g_filename_display_name(ns); - g_free(ns); - end else Result := ns; + nss := g_filename_display_name(ns); + Result := strdup(nss); // PPC compatibility + g_free(nss); + end else Result := strdup(ns); // PPC compatibility + g_free(ns); end; function UTF8ToStr(s: PChar): PChar; -- cgit v1.2.3