diff options
Diffstat (limited to 'openbsd-compat/realpath.c')
-rw-r--r-- | openbsd-compat/realpath.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/openbsd-compat/realpath.c b/openbsd-compat/realpath.c index ec801d498..b4a05db95 100644 --- a/openbsd-compat/realpath.c +++ b/openbsd-compat/realpath.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) | 32 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) |
33 | 33 | ||
34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
35 | static char *rcsid = "$OpenBSD: realpath.c,v 1.5 2001/06/27 00:58:56 lebel Exp $"; | 35 | static char *rcsid = "$OpenBSD: realpath.c,v 1.6 2002/01/12 16:24:35 millert Exp $"; |
36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
37 | 37 | ||
38 | #include <sys/param.h> | 38 | #include <sys/param.h> |
@@ -74,6 +74,10 @@ realpath(const char *path, char *resolved) | |||
74 | } | 74 | } |
75 | close(fd); | 75 | close(fd); |
76 | 76 | ||
77 | /* Convert "." -> "" to optimize away a needless lstat() and chdir() */ | ||
78 | if (path[0] == '.' && path[1] == '\0') | ||
79 | path = ""; | ||
80 | |||
77 | /* | 81 | /* |
78 | * Find the dirname and basename from the path to be resolved. | 82 | * Find the dirname and basename from the path to be resolved. |
79 | * Change directory to the dirname component. | 83 | * Change directory to the dirname component. |
@@ -102,7 +106,7 @@ loop: | |||
102 | p = resolved; | 106 | p = resolved; |
103 | 107 | ||
104 | /* Deal with the last component. */ | 108 | /* Deal with the last component. */ |
105 | if (lstat(p, &sb) == 0) { | 109 | if (*p != '\0' && lstat(p, &sb) == 0) { |
106 | if (S_ISLNK(sb.st_mode)) { | 110 | if (S_ISLNK(sb.st_mode)) { |
107 | if (++symlinks > MAXSYMLINKS) { | 111 | if (++symlinks > MAXSYMLINKS) { |
108 | serrno = ELOOP; | 112 | serrno = ELOOP; |