| version 1.34, 2005/01/06 23:43:32 |
version 1.35, 2005/01/23 01:00:51 |
| Line 61 __weak_alias(getcwd,_getcwd) |
|
| Line 61 __weak_alias(getcwd,_getcwd) |
|
| __weak_alias(realpath,_realpath) |
__weak_alias(realpath,_realpath) |
| #endif |
#endif |
| |
|
| #define ISDOT(dp) \ |
|
| (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ |
|
| (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) |
|
| |
|
| |
|
| #if defined(__SVR4) || defined(__svr4__) |
|
| #define d_fileno d_ino |
|
| #endif |
|
| |
|
| /* |
/* |
| * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); |
* char *realpath(const char *path, char resolved_path[MAXPATHLEN]); |
| * |
* |
| Line 205 err2: (void)close(fd); |
|
| Line 196 err2: (void)close(fd); |
|
| } |
} |
| |
|
| char * |
char * |
| getcwd(pt, size) |
getcwd(char *pt, size_t size) |
| char *pt; |
|
| size_t size; |
|
| { |
{ |
| size_t ptsize, bufsize; |
char *npt; |
| int len; |
|
| |
|
| /* |
/* |
| * If no buffer specified by the user, allocate one as necessary. |
* If a buffer is specified, the size has to be non-zero. |
| * If a buffer is specified, the size has to be non-zero. The path |
|
| * is built from the end of the buffer backwards. |
|
| */ |
*/ |
| if (pt) { |
if (pt != NULL) { |
| ptsize = 0; |
if (size == 0) { |
| if (!size) { |
/* __getcwd(pt, 0) results ERANGE. */ |
| errno = EINVAL; |
errno = EINVAL; |
| return (NULL); |
return (NULL); |
| } |
} |
| bufsize = size; |
if (__getcwd(pt, size) >= 0) |
| } else { |
return (pt); |
| if ((pt = malloc(ptsize = 1024 - 4)) == NULL) |
return (NULL); |
| return (NULL); |
|
| bufsize = ptsize; |
|
| } |
|
| for (;;) { |
|
| len = __getcwd(pt, bufsize); |
|
| if ((len < 0) && (size == 0) && (errno == ERANGE)) { |
|
| if (ptsize > (MAXPATHLEN*4)) |
|
| return NULL; |
|
| if ((pt = realloc(pt, ptsize *= 2)) == NULL) |
|
| return NULL; |
|
| bufsize = ptsize; |
|
| continue; |
|
| } |
|
| break; |
|
| } |
} |
| if (len < 0) |
|
| return NULL; |
/* |
| else |
* If no buffer specified by the user, allocate one as necessary. |
| return pt; |
*/ |
| |
size = 1024 >> 1; |
| |
do { |
| |
if ((npt = realloc(pt, size <<= 1)) == NULL) |
| |
break; |
| |
pt = npt; |
| |
if (__getcwd(pt, size) >= 0) |
| |
return (pt); |
| |
} while (size <= MAXPATHLEN * 4 && errno == ERANGE); |
| |
|
| |
free(pt); |
| |
return (NULL); |
| } |
} |