Browse Source

* default to UTF-8 as system code page in case nl_langinfo(CODESET) returns
an empty string

git-svn-id: trunk@19964 -

Jonas Maebe 13 years ago
parent
commit
f287cf3f61
1 changed files with 11 additions and 1 deletions
  1. 11 1
      rtl/unix/cwstring.pp

+ 11 - 1
rtl/unix/cwstring.pp

@@ -874,8 +874,18 @@ begin
 end;
 end;
 
 
 function GetStandardCodePage(const stdcp: TStandardCodePageEnum): TSystemCodePage;
 function GetStandardCodePage(const stdcp: TStandardCodePageEnum): TSystemCodePage;
+var
+  langinfo: pchar;
 begin
 begin
-  Result := iconv2win(ansistring(nl_langinfo(CODESET)))
+  langinfo:=nl_langinfo(CODESET);
+  { there's a bug in the Mac OS X 10.5 libc (based on FreeBSD's)
+    that causes it to return an empty string of UTF-8 locales
+    -> patch up (and in general, UTF-8 is a good default on
+    Unix platforms) }
+  if not assigned(langinfo) or
+     (langinfo^=#0) then
+    langinfo:='UTF-8';
+  Result := iconv2win(ansistring(langinfo));
 end;
 end;
 
 
 {$ifdef FPC_HAS_CPSTRING}
 {$ifdef FPC_HAS_CPSTRING}