Symbolic links question - getwd() bug fix

John Bruner jdb at mordor.UUCP
Tue Jul 3 03:00:57 AEST 1984


There is a case in which "pwd" will use a soft link to a directory
in preference to a hard link.  This will occur if the symbolic link
resides in the same directory as the hard link, and the entry for
the symbolic link appears first in the parent directory.
For example, if "/" contains the entries

	/u -> /usr
	/usr

in that order, the command "cd /usr;pwd" will return "/u".

The actual work is done by the library routine getwd() (source
"/src/lib/libc/gen/getwd.c").  It is unable to distinguish the
soft link from the hard link because it uses stat().  Changing
all stat() calls to lstat() will force it to always return
the "real" pathname.
-- 
  John Bruner (S-1 Project, Lawrence Livermore National Laboratory)
  MILNET: jdb at mordor.ARPA [jdb at s1-c]	(415) 422-0758
  UUCP: ...!ucbvax!dual!mordor!jdb 	...!decvax!decwrl!mordor!jdb



More information about the Comp.unix mailing list