|
@ -35,7 +35,7 @@ |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
#if defined(LIBC_SCCS) && !defined(lint) |
|
|
static char *rcsid = "$OpenBSD: realpath.c,v 1.2 1996/08/19 08:33:47 tholo Exp $"; |
|
|
|
|
|
|
|
|
static char *rcsid = "$OpenBSD: realpath.c,v 1.3 1997/06/20 20:37:45 deraadt Exp $"; |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
#endif /* LIBC_SCCS and not lint */ |
|
|
|
|
|
|
|
|
#include <sys/param.h> |
|
|
#include <sys/param.h> |
|
@ -62,6 +62,7 @@ realpath(path, resolved) |
|
|
struct stat sb; |
|
|
struct stat sb; |
|
|
int fd, n, rootd, serrno; |
|
|
int fd, n, rootd, serrno; |
|
|
char *p, *q, wbuf[MAXPATHLEN]; |
|
|
char *p, *q, wbuf[MAXPATHLEN]; |
|
|
|
|
|
int symlinks = 0; |
|
|
|
|
|
|
|
|
/* Save the starting point. */ |
|
|
/* Save the starting point. */ |
|
|
if ((fd = open(".", O_RDONLY)) < 0) { |
|
|
if ((fd = open(".", O_RDONLY)) < 0) { |
|
@ -100,6 +101,10 @@ loop: |
|
|
/* Deal with the last component. */ |
|
|
/* Deal with the last component. */ |
|
|
if (lstat(p, &sb) == 0) { |
|
|
if (lstat(p, &sb) == 0) { |
|
|
if (S_ISLNK(sb.st_mode)) { |
|
|
if (S_ISLNK(sb.st_mode)) { |
|
|
|
|
|
if (++symlinks > MAXSYMLINKS) { |
|
|
|
|
|
errno = ELOOP; |
|
|
|
|
|
goto err1; |
|
|
|
|
|
} |
|
|
n = readlink(p, resolved, MAXPATHLEN); |
|
|
n = readlink(p, resolved, MAXPATHLEN); |
|
|
if (n < 0) |
|
|
if (n < 0) |
|
|
goto err1; |
|
|
goto err1; |
|
|