version 1.20, 1999/07/11 18:01:46 |
version 1.22, 1999/09/16 11:44:58 |
Line 49 __RCSID("$NetBSD$"); |
|
Line 49 __RCSID("$NetBSD$"); |
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
|
#include <assert.h> |
#include <dirent.h> |
#include <dirent.h> |
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
Line 86 realpath(path, resolved) |
|
Line 87 realpath(path, resolved) |
|
char *resolved; |
char *resolved; |
{ |
{ |
struct stat sb; |
struct stat sb; |
int fd, n, rootd, serrno; |
int fd, n, rootd, serrno, nlnk = 0; |
char *p, *q, wbuf[MAXPATHLEN]; |
char *p, *q, wbuf[MAXPATHLEN]; |
|
|
|
_DIAGASSERT(path != NULL); |
|
_DIAGASSERT(resolved != NULL); |
|
#ifdef _DIAGNOSTIC |
|
if (path == NULL || *path == '\0') { |
|
errno = ENOENT; |
|
return (NULL); |
|
} |
|
if (resolved == NULL) { |
|
errno = EINVAL; |
|
return (NULL); |
|
} |
|
#endif |
|
|
/* Save the starting point. */ |
/* Save the starting point. */ |
if ((fd = open(".", O_RDONLY)) < 0) { |
if ((fd = open(".", O_RDONLY)) < 0) { |
(void)strcpy(resolved, "."); |
(void)strcpy(resolved, "."); |
|
|
/* 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 (nlnk++ >= 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; |