getpwent() home directory v/s getcwd()
By templedf on Jul 14, 2004
Here's the story: I call getpwent() to get a user's home directory. I also have a list of path aliases in a file that I will use to replace paths I'm given. The paths in the path alias file and the home directory from getpwent() are logical paths, e.g. /home/dant. Now, in my code, I need to be able to recognize an aliased path when I see it. The problem is that the paths I'm being given are physical paths, e.g. /tmpmnt/home/dant.
The current solution is to chdir() to the home directory and use getcwd() to get the physical path for it. Then, if I see that physical path in a path I'm given, I can replace that part of the path with the logical home directory and then look the logical path up in the path alias list.
The problem with the current solution is that I have to chdir() to do it, which is not thread safe. Can anyone lend me any clever insight into how to solve this problem cleanly?