C: expanding "~user" notation
Does anyone know of a simple way to find the home directory of a user if the path is given as "~user/path/to/somewhere"? I'm looking for anything... personal code you've developed or a library routine you might know of.
I can't find anything appropriate with apropos and searching for "home directory program username" on Google still gives no meaningful results... not sure how else I could refine the search.
I can write a parsing routine, but don't want to reinvent the wheel, and I know the wheel has been invented somewhere out there.
I know I can call popen() with a piped sequence sequence of commands to pull the information out of /etc/passwd ("grep '^<username>:' /etc/passwd | cut -f 5 -d ':'"), but I want to leave that as a last resort.
I know the above might sound picky (maybe even a lot), but I would really appreciate any code or just a nudge in the right direction.
Thanks.
|