summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/realpath.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2002-01-12 16:24:35 +0000
committermillert <millert@openbsd.org>2002-01-12 16:24:35 +0000
commit05c975373358c5121cda976300fc594ce1f665ac (patch)
treee4f4f5fd30828ba8b40ba1db0627b34c2c69d92b /lib/libc/stdlib/realpath.c
parent o Don't use register except in conjunction with assembler (diff)
downloadwireguard-openbsd-05c975373358c5121cda976300fc594ce1f665ac.tar.xz
wireguard-openbsd-05c975373358c5121cda976300fc594ce1f665ac.zip
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.
Diffstat (limited to 'lib/libc/stdlib/realpath.c')
-rw-r--r--lib/libc/stdlib/realpath.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c
index a6195c1dcbd..061f1a7ef12 100644
--- a/lib/libc/stdlib/realpath.c
+++ b/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 <sys/param.h>
@@ -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;