[fpc-pascal] locale solution for unix systems

Graeme Geldenhuys graemeg.lists at gmail.com
Sun Mar 22 07:37:35 CET 2009


On Fri, Mar 20, 2009 at 5:04 PM, Henry Vermaak <henry.vermaak at gmail.com> wrote:
>
> but fpgui depends on x, right?  and x depends on libc?  you might as
> well include clocales by default under an ifdef (like lazarus does
> with cthreads).

fpGUI depends on libx11 for X11 based systems. Also on embedded ARM
systems (tested by you).

But last time I tested libc was not available for FreeBSD. Hence the
reason I have code as follows (which only includes libc when the OS is
Linux on cpu386).

getpwuid(...)
getgrgid(...)

did not work under FreeBSD or DesktopBSD.

==========================
implementation

uses
  baseunix,
  // Graeme: temporary. libc is not available for FreeBSD.
  {$if defined(linux) and defined(cpu386)}libc,{$endif}
  ...

[.....snip.....]
{$if defined(linux) and defined(cpu386)}
function TfpgFileListImpl.GetUserName(uid: integer): string;
var
  p: PPasswd;
begin
  p := getpwuid(uid);
  if p <> nil then
    result := p^.pw_name
  else
    result := '';
end;
{$else}
// Still need to find an alternative for FreeBSD as we can't use the libc unit.
function TfpgFileListImpl.GetUserName(uid: integer): string;
begin
  result := IntToStr(uid);
end;
{$endif}


{$if defined(linux) and defined(cpu386)}
function TfpgFileListImpl.GetGroupName(gid: integer): string;
var
  p: PGroup;
begin
  p := getgrgid(gid);
  if p <> nil then
    result := p^.gr_name;
end;

{$else}
// Still need to find an alternative for FreeBSD as we can't use the libc unit.
function TfpgFileListImpl.GetGroupName(gid: integer): string;
begin
  result := IntToStr(gid);
end;
{$endif}
==========================


Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list