Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-01

libc unit and FreeBSD

9 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

As far as I understand the 'libc' unit is a compatibility unit from the Kylix days and is only meant for linux/x86, so isn't portable.

I'm trying to get fpGUI working under FreeBSD but hit a snag in my File Grid component. The File Grid component displays a directory in a grid (think File Dialog here) and shows the file permissions, file group name and file user name. The code to get the group name and user name uses methods & types from the libc unit, so I'm not able to compile it under FreeBSD.

Anybody know if there is a generic set of methods that supports all (or most) unix style OS's? I looked in 'baseunix', but there the group and name methods relate to a process id's, not to file attributes...

The offending code is as follows...

function GetGroupName(gid: integer): string;
var
  p: PGroup;
begin
  p := getgrgid(gid);
  if p  nil then
    result := p^.gr_name;
end;
function GetUserName(uid: integer): string;
var
  p: PPasswd;
begin
  p := getpwuid(uid);
  if p  nil then
    result := p^.pw_name
  else
    result := '';
end;

Many thanks in advance.

Regards,
- Graeme -

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

Daniël Mantione
to Graeme Geldenhuys

Op Mon, 14 Jan 2008, schreef Graeme Geldenhuys:

Show quoted text 16 lines
Hi, As far as I understand the 'libc' unit is a compatibility unit from the Kylix days and is only meant for linux/x86, so isn't portable. I'm trying to get fpGUI working under FreeBSD but hit a snag in my File Grid component. The File Grid component displays a directory in a grid (think File Dialog here) and shows the file permissions, file group name and file user name. The code to get the group name and user name uses methods & types from the libc unit, so I'm not able to compile it under FreeBSD. Anybody know if there is a generic set of methods that supports all (or most) unix style OS's? I looked in 'baseunix', but there the group and name methods relate to a process id's, not to file attributes...

You hit an area that is problematic to implement without libc. Libc has plugins (libnss*) so user data can be stored in files in /etc, yellow pages, databases, ldap, windows servers, and so on.

The only thing we could do to it without libc and without rewriting all those plugins is to load the nss plugins from Pascal. However, this would be Linux specific code, other Unixes likely need a different implementation.

Daniël

Graeme Geldenhuys
to Daniël Mantione
Daniël Mantione wrote 6 lines
> Anybody know if there is a generic set of methods that supports all > (or most) unix style OS's? I looked in 'baseunix', but there the > group and name methods relate to a process id's, not to file > attributes... You hit an area that is problematic to implement without libc. Libc has

My alternative is then to maybe drop the idea of showing Permisions, GroupName and UserName in the file dialogs. I did a quick look and GTK2 and Qt based applications that use File Dialogs don't show that information either. GTK1 being the exception. So I guess it wouldn't be too bad.

For interest sake, I'm going to download the GTK1 source to see what they did to get around the issue under different unix type OS's. Except it they did like you said and used libc plugins under FreeBSD + GTK1 (I honestly don't know that much about libc)?

Regards,
- Graeme -

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

Marco van de Voort
to Graeme Geldenhuys: As far as I understand the 'libc' unit is a compatibility unit from the Kylix days and is…
Anybody know if there is a generic set of methods that supports all (or most) unix style OS's? I looked in 'baseunix', but there the group and name methods relate to a process id's, not to file attributes...

Baseunix and Unix should be implementable without libc for maximal portability. But, as Daniel says, these functions are not so nice to implement without libc because of directory plugins.

Ales and I discussed about this a way back, (then because of netdb, DNS resolving having a bit of the same problem), and the conclusion was to have a few "C" units (cpwd cnetdb) and advocate them for normal use, and if sb develops libcless equivalents (as we already have for netdb), put them in corresponding unit (pwd,netdb), for installer/bootstrap use. Specially with a download-package tool this is getting more important.

Since messing with netdb always eats up a lot of time, it got on the back burner.

Anybody a better name then (c)pwd ?

Michael Van Canneyt
to Marco van de Voort
Marco van de Voort wrote 20 lines
> Anybody know if there is a generic set of methods that supports all > (or most) unix style OS's? I looked in 'baseunix', but there the > group and name methods relate to a process id's, not to file > attributes... Baseunix and Unix should be implementable without libc for maximal portability. But, as Daniel says, these functions are not so nice to implement without libc because of directory plugins. Ales and I discussed about this a way back, (then because of netdb, DNS resolving having a bit of the same problem), and the conclusion was to have a few "C" units (cpwd cnetdb) and advocate them for normal use, and if sb develops libcless equivalents (as we already have for netdb), put them in corresponding unit (pwd,netdb), for installer/bootstrap use. Specially with a download-package tool this is getting more important. Since messing with netdb always eats up a lot of time, it got on the back burner. Anybody a better name then (c)pwd ?

cpasswd is more clear to me. I had to read your mail twice in order to understand what cpwd meant.

Michael.

Graeme Geldenhuys
to Graeme Geldenhuys: My alternative is then to maybe drop the idea of showing Permisions, GroupName and…

Hi,

For now I wrapped the libc calls with $IFDEF LINUX and for other unix variants I simply return the Group ID and User ID (instead of the more friend names).

A quick work-around for me would be to read the /etc/groups and /etc/passwd files looking for the Group ID or User ID and return the associated names. I can parse and keep a copy of those files in memory while the File Dialog is open - than way it should speed up the lookups as the user browses through directories.

Does anybody know if unix type OS's allow normal (general) users to read those files from /etc?
Under Linux it's allowed. I'll have to wait until I'm home to check if FreeBSD allows that.

Other than the above, fpGUI doesn't use any other libc calls, so hopefully tonight I'll can confirm if FreeBSD is a newly supported OS. :)

Regards,
- Graeme -

Graeme Geldenhuys wrote 29 lines
On 14/01/2008, Daniël Mantione wrote: > > Anybody know if there is a generic set of methods that supports all > > (or most) unix style OS's? I looked in 'baseunix', but there the > > group and name methods relate to a process id's, not to file > > attributes... > > You hit an area that is problematic to implement without libc. Libc has My alternative is then to maybe drop the idea of showing Permisions, GroupName and UserName in the file dialogs. I did a quick look and GTK2 and Qt based applications that use File Dialogs don't show that information either. GTK1 being the exception. So I guess it wouldn't be too bad. For interest sake, I'm going to download the GTK1 source to see what they did to get around the issue under different unix type OS's. Except it they did like you said and used libc plugins under FreeBSD + GTK1 (I honestly don't know that much about libc)? Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/
Marc Santhoff
to Graeme Geldenhuys: As far as I understand the 'libc' unit is a compatibility unit from the Kylix days and is…
Graeme Geldenhuys wrote 21 lines
The offending code is as follows... function GetGroupName(gid: integer): string; var p: PGroup; begin p := getgrgid(gid); if p nil then result := p^.gr_name; end; function GetUserName(uid: integer): string; var p: PPasswd; begin p := getpwuid(uid); if p nil then result := p^.pw_name else result := ''; end;

The functions getlogin(2), getpwnam(3) and getgrnam(3) should be it. Look at the man pages how to use them.
(this is on freebsd 4, should not have changed moving to 6 or 7)

I don't know if they are wrapped by fpc or what the names would be (maybe fpXxxx as always).

HTH,
Marc

Jonas Maebe
to Graeme Geldenhuys: For now I wrapped the libc calls with $IFDEF LINUX and for other unix variants I simply…
Graeme Geldenhuys wrote 8 lines
A quick work-around for me would be to read the /etc/groups and /etc/passwd files looking for the Group ID or User ID and return the associated names. I can parse and keep a copy of those files in memory while the File Dialog is open - than way it should speed up the lookups as the user browses through directories. Does anybody know if unix type OS's allow normal (general) users to read those files from /etc?

Yes, but they they do not necessarily contain any useful information. The actually used information may be on an ldap server, in a netinfo database, on an NIS server, on a SAMBA server, on a Windows Domain Controller, ... That's the whole point of the plugin system used by libc.

Jonas

Graeme Geldenhuys
to Jonas Maebe
Jonas Maebe wrote 8 lines
> Does anybody know if unix type OS's allow normal (general) users to > read those files from /etc? Yes, but they they do not necessarily contain any useful information. The actually used information may be on an ldap server, in a netinfo database, on an NIS server, on a SAMBA server, on a Windows Domain Controller, ... That's the whole point of the plugin system used by libc.

Ah, now I get it. Thanks.

Regards,
- Graeme -

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