|
From: Robert W. <rj...@du...> - 2004-01-08 18:52:03
|
> I'm working on this, and I want to read ~/.valgrindrc. However, I can't
> use '~' in C because it's a shell thing, I think.
>
> How can I find the home directory -- is getenv("HOME") the right way?
> (Is $HOME always defined?)
It's not guaranteed to be, but it nearly always is. Another way is to
use getpwuid(getuid()) and pull out the pw_dir field from the result.
That should always work, unless the UID isn't in your password
database. Happily, with full virtualisation, this should now be usable
(getpwuid() is in libc, and actually more complicated than you might
imagine since it has to handle NIS, /etc/passwd, LDAP, etc.)
Regards,
Robert.
|