Jon Steinhart <[EMAIL PROTECTED]> writes: > 3. If the $HOME environment variable is set, mypath is copied from the > getenv return. Why? It's never changed. > > 4. If the $HOME environment variable is not set, mypath is copied from the > pw_dir member of the returned passwd structure. Now, I understand that > this is a static structure, but getpwuid is never called again so I > don't see why the copy is needed. > > 4. If the $HOME environment variable is not set, the pw_dir member of the > passwd structure returned by getpwuid() is checked for a NULL pointer. > This can never happen in a non-error return, which is already checked. > So why the superfluous check?
These checks are not superflous, they are for maintainability. Two years from now someone will add a second getenv(3) call and waste their (probably volunteer) time trying to figure out how they busted the home dir variable. That is why, unless you are writing super-tight-must-be-the-best-performing-code-ever applications (which mh is not), it is necessary always to make a copy of the static buffer pointed to by the return values of such functions. -- Eric Gillespie <*> [EMAIL PROTECTED] Build a fire for a man, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life. -Terry Pratchett