|
|
@ -31,7 +31,7 @@ |
|
|
|
*/ |
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
|
static char *rcsid = "$OpenBSD: realpath.c,v 1.9 2003/06/02 20:18:38 millert Exp $"; |
|
|
|
static char *rcsid = "$OpenBSD: realpath.c,v 1.10 2003/08/01 21:04:59 millert Exp $"; |
|
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
#include <sys/param.h> |
|
|
@ -56,7 +56,7 @@ realpath(path, resolved) |
|
|
|
char *resolved; |
|
|
|
{ |
|
|
|
struct stat sb; |
|
|
|
int fd, n, rootd, serrno; |
|
|
|
int fd, n, needslash, serrno; |
|
|
|
char *p, *q, wbuf[MAXPATHLEN]; |
|
|
|
int symlinks = 0; |
|
|
|
|
|
|
@ -130,16 +130,16 @@ loop: |
|
|
|
* happens if the last component is empty, or the dirname is root. |
|
|
|
*/ |
|
|
|
if (resolved[0] == '/' && resolved[1] == '\0') |
|
|
|
rootd = 1; |
|
|
|
needslash = 0; |
|
|
|
else |
|
|
|
rootd = 0; |
|
|
|
needslash = 1; |
|
|
|
|
|
|
|
if (*wbuf) { |
|
|
|
if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { |
|
|
|
if (strlen(resolved) + strlen(wbuf) + needslash >= MAXPATHLEN) { |
|
|
|
errno = ENAMETOOLONG; |
|
|
|
goto err1; |
|
|
|
} |
|
|
|
if (rootd == 0) |
|
|
|
if (needslash) |
|
|
|
strlcat(resolved, "/", MAXPATHLEN); |
|
|
|
strlcat(resolved, wbuf, MAXPATHLEN); |
|
|
|
} |
|
|
|