@ -35,7 +35,7 @@
*/
*/
# if defined(LIBC_SCCS) && !defined(lint)
# if defined(LIBC_SCCS) && !defined(lint)
static char * rcsid = " $OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $ " ;
static char * rcsid = " $OpenBSD: realpath.c,v 1.6 2002/01/12 16:24:35 millert Exp $ " ;
# endif /* LIBC_SCCS and not lint */
# endif /* LIBC_SCCS and not lint */
# include <sys/param.h>
# include <sys/param.h>
@ -70,6 +70,10 @@ realpath(path, resolved)
return ( NULL ) ;
return ( NULL ) ;
}
}
/* Convert "." -> "" to optimize away a needless lstat() and chdir() */
if ( path [ 0 ] = = ' . ' & & path [ 1 ] = = ' \0 ' )
path = " " ;
/*
/*
* Find the dirname and basename from the path to be resolved .
* Find the dirname and basename from the path to be resolved .
* Change directory to the dirname component .
* Change directory to the dirname component .
@ -98,7 +102,7 @@ loop:
p = resolved ;
p = resolved ;
/* Deal with the last component. */
/* Deal with the last component. */
if ( lstat ( p , & sb ) = = 0 ) {
if ( * p ! = ' \0 ' & & lstat ( p , & sb ) = = 0 ) {
if ( S_ISLNK ( sb . st_mode ) ) {
if ( S_ISLNK ( sb . st_mode ) ) {
if ( + + symlinks > MAXSYMLINKS ) {
if ( + + symlinks > MAXSYMLINKS ) {
errno = ELOOP ;
errno = ELOOP ;