Subject: Re: lib/30943: realpath() behaviour changed with nonexistant relative path
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Mark Davies <mark@mcs.vuw.ac.nz>
List: netbsd-bugs
Date: 08/13/2005 10:39:01
The following reply was made to PR lib/30943; it has been noted by GNATS.

From: Mark Davies <mark@mcs.vuw.ac.nz>
To: Elad Efrat <elad@netbsd.org>
Cc: gnats-bugs@netbsd.org
Subject: Re: lib/30943: realpath() behaviour changed with nonexistant relative path
Date: Sat, 13 Aug 2005 22:37:46 +1200

 On Saturday 13 August 2005 20:13, Elad Efrat wrote:
 > Yeah, but like martin@ pointed out - how much will it hurt existing
 > programs?
 
 Well if the existing programs are at all designed to be portable across 
 systems then it wont hurt them at all since it will be conforming to the 
 behavior they expect.  If they are *BSD specific then they might be relying 
 on the "nonexistant last element" behavior but they certainly wont be relying 
 on the "nonexistant element with trailing slash" since that doesn't succeed 
 on the other BSD's and didn't use to work on NetBSD.  And as I mentioned in 
 the original PR the current behavior hurts existing programs (specifically 
 KDE).
 
 So the minimal fix would be to restore the traditional *BSD behavior which the 
 following patch would do:
 
 Index: getcwd.c
 ===================================================================
 RCS file: /src/cvs/netbsd/src/lib/libc/gen/getcwd.c,v
 retrieving revision 1.38
 diff -u -r1.38 getcwd.c
 --- getcwd.c	5 Jul 2005 02:56:12 -0000	1.38
 +++ getcwd.c	13 Aug 2005 10:19:26 -0000
 @@ -160,8 +160,6 @@
  	 */
  	if (lstat(resolved, &sb) == -1) {
  		/* Allow nonexistent component if this is the last one. */
 -		while (*q == '/')
 -			q++;
  		if (*q == 0 && errno == ENOENT) {
  			errno = serrno;
  			return (resolved);
 
 
 and you could argue that this is consistent with comment and manual page in 
 that by having the trailing "/" you are explicitly adding a "null" component 
 on the end so that the nonexistant one is not last.
 
 cheers
 mark