version 1.19, 1999/06/11 15:38:40 |
version 1.24.6.3, 2002/12/10 06:25:48 |
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 60 __RCSID("$NetBSD$"); |
|
Line 61 __RCSID("$NetBSD$"); |
|
#include "extern.h" |
#include "extern.h" |
|
|
#ifdef __weak_alias |
#ifdef __weak_alias |
__weak_alias(getcwd,_getcwd); |
__weak_alias(getcwd,_getcwd) |
__weak_alias(realpath,_realpath); |
__weak_alias(realpath,_realpath) |
#endif |
#endif |
|
|
#define ISDOT(dp) \ |
#define ISDOT(dp) \ |
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); |
|
|
/* Save the starting point. */ |
/* Save the starting point. */ |
if ((fd = open(".", O_RDONLY)) < 0) { |
if ((fd = open(".", O_RDONLY)) < 0) { |
(void)strcpy(resolved, "."); |
(void)strlcpy(resolved, ".", MAXPATHLEN); |
return (NULL); |
return (NULL); |
} |
} |
|
|
Line 103 realpath(path, resolved) |
|
Line 107 realpath(path, resolved) |
|
* if it is a directory, then change to that directory. |
* if it is a directory, then change to that directory. |
* get the current directory name and append the basename. |
* get the current directory name and append the basename. |
*/ |
*/ |
(void)strncpy(resolved, path, MAXPATHLEN - 1); |
(void)strlcpy(resolved, path, MAXPATHLEN); |
resolved[MAXPATHLEN - 1] = '\0'; |
|
loop: |
loop: |
q = strrchr(resolved, '/'); |
q = strrchr(resolved, '/'); |
if (q != NULL) { |
if (q != NULL) { |
|
|
/* 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)) { |
n = readlink(p, resolved, MAXPATHLEN); |
if (nlnk++ >= MAXSYMLINKS) { |
|
errno = ELOOP; |
|
goto err1; |
|
} |
|
n = readlink(p, resolved, MAXPATHLEN-1); |
if (n < 0) |
if (n < 0) |
goto err1; |
goto err1; |
resolved[n] = '\0'; |
resolved[n] = '\0'; |
|
|
* Save the last component name and get the full pathname of |
* Save the last component name and get the full pathname of |
* the current directory. |
* the current directory. |
*/ |
*/ |
(void)strncpy(wbuf, p, (sizeof(wbuf) - 1)); |
(void)strlcpy(wbuf, p, sizeof(wbuf)); |
|
|
/* |
/* |
* Call the inernal internal version of getcwd which |
* Call the inernal internal version of getcwd which |
Line 412 getcwd(pt, size) |
|
Line 419 getcwd(pt, size) |
|
for (;;) { |
for (;;) { |
len = __getcwd(pt, bufsize); |
len = __getcwd(pt, bufsize); |
if ((len < 0) && (size == 0) && (errno == ERANGE)) { |
if ((len < 0) && (size == 0) && (errno == ERANGE)) { |
|
if (ptsize > (MAXPATHLEN*4)) |
|
return NULL; |
if ((pt = realloc(pt, ptsize *= 2)) == NULL) |
if ((pt = realloc(pt, ptsize *= 2)) == NULL) |
return NULL; |
return NULL; |
bufsize = ptsize; |
bufsize = ptsize; |