C/C++ - Locating a user's home directory
David Fletcher
dave at thefletchers.net
Sat Jan 29 18:32:20 UTC 2011
On Sat, 2011-01-29 at 11:13 -0700, Smoot Carl-Mitchell wrote:
> On Sat, 2011-01-29 at 16:58 +0000, David Fletcher wrote:
> > I'm writing a small C++ application that I want to run once a day as an
> > ordinary user on my server as a cron job. The application is almost
> > complete, except that what I want to do is get it to use config files in
> > the user's home directory.
>
> You can look up the home directory by doing a getpwuid(uid) call which
> is in the C library. Look at the getpwent man page for the structure of
> the returned value. The home directory is a field in the returned
> structure.
>
> Also if you run the program out of cron, the current working directory
> of the program is the home directory of the user.
>
Thanks ever so much. That looks like it's exactly what I need. I'll have
a fiddle with it later.
Dave
More information about the ubuntu-users
mailing list