[fpc-pascal]How to get the Home Directory of the user?
ddt at headrush.co.za
ddt at headrush.co.za
Tue Sep 10 00:17:40 CEST 2002
I missed the rest of this thread, but in case you still want to know,
the very easiest way to get the users home directory:
Uses linux;
Var
HomeDir :String
<snip>
HomeDir := GetENV('HOME');
Original Message:
-----------------
From: Hélio Cavichiolo Jr helio at definitylinux.com.br
Date: Mon, 9 Sep 2002 12:22:08 -0300 (BRT)
To: fpc-pascal at deadlock.et.tudelft.nl
Subject: Re: [fpc-pascal]How to get the Home Directory of the user?
> On Fri, 6 Sep 2002, [iso-8859-1] Hélio Cavichiolo Jr wrote:
>
>> How to check if a call to getpwnam had success?
>> How to change user information?
And the above questions, anyone knows the answers?
>>
>> I made this program to test but the 'if' never matches.
>> Entering a valid user, I had to remove de 'if' to see user's gecos, by
>> the other hand, entering an invalid user, the program crashes on the
>> 'if'.
>
> You are trying to compare strings with pchars; this will not work.
>
>>
>> program test;
>>
>> uses
>> pwdlibc;
>>
>> var
>> pwd : pPasswd;
>> user: pChar;
>
> You should define this as a string. Define a second pchar 'puser';
> user : string;
> puser : pchar;
>
>>
>> begin
>> user := '';
>> write('Usuário: ');
>> readln(user);
>
> Add here
>
> user:=user+#0;
> puser:=@user[1];
>
>> pwd := Getpwnam(user);
>> if user = pwd^.pw_name then
>
> Change the above by
> if strcmp(puser,pwd^.pw_name)=0 then
I think you mean strcomp from strings unit, right?
It works if user exists, otherwise the program crashes. I think there is
another way to know when the Getpwname returns ok or fail.
>
> and it should work.
>
> Michael.
>> begin
>> writeln('(',pwd^.pw_name,')');
>> writeln('(',pwd^.pw_gecos,')');
>> end
>> else
>> writeln(user,' not found!');
>> end.
>>
--
Helio Cavichiolo Jr
Analista de Sistemas
Esc Telecomunicações Ltda
D e f i n i t y L i n u x
_______________________________________________
fpc-pascal maillist -
pascal at lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .
More information about the fpc-pascal
mailing list