From ab193f788e40e3bc214a6c15e3bd5171dd7b163d Mon Sep 17 00:00:00 2001 From: millert <> Date: Sat, 12 Jan 2002 16:24:35 +0000 Subject: If the user passes in "" as the string to resolve the lstat() will fail anyway so check for that. Also convert "." to "" since that way we avoid the lstat() (which we don't need) and the subsequent chdir() and some dir checks. --- src/lib/libc/stdlib/realpath.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libc/stdlib/realpath.c b/src/lib/libc/stdlib/realpath.c index a6195c1dcb..061f1a7ef1 100644 --- a/src/lib/libc/stdlib/realpath.c +++ b/src/lib/libc/stdlib/realpath.c @@ -35,7 +35,7 @@ */ #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 */ #include @@ -70,6 +70,10 @@ realpath(path, resolved) 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. * Change directory to the dirname component. @@ -98,7 +102,7 @@ loop: p = resolved; /* Deal with the last component. */ - if (lstat(p, &sb) == 0) { + if (*p != '\0' && lstat(p, &sb) == 0) { if (S_ISLNK(sb.st_mode)) { if (++symlinks > MAXSYMLINKS) { errno = ELOOP; -- cgit v1.2.3-55-g6feb