version 1.17, 2002/02/19 19:39:38 |
version 1.18, 2002/05/29 09:23:25 |
|
|
{ |
{ |
static char buf[100]; |
static char buf[100]; |
if (e < 0 || e >= sys_nerr) { |
if (e < 0 || e >= sys_nerr) { |
sprintf(buf, "Unknown error %d", e); |
snprintf(buf, sizeof buf, "Unknown error %d", e); |
return buf; |
return buf; |
} |
} |
else |
else |
|
|
/* find the inode of root */ |
/* find the inode of root */ |
if (stat("/", &st_root) == -1) { |
if (stat("/", &st_root) == -1) { |
(void)sprintf(pathname, |
(void)sprintf(pathname, |
"getwd: Cannot stat \"/\" (%s)", strerror(errno)); |
"getwd: Cannot stat \"/\" (%s)", strerror(errno)); |
return NULL; |
return NULL; |
} |
} |
pathbuf[MAXPATHLEN - 1] = '\0'; |
pathbuf[MAXPATHLEN - 1] = '\0'; |
|
|
/* find the inode of the current directory */ |
/* find the inode of the current directory */ |
if (lstat(".", &st_cur) == -1) { |
if (lstat(".", &st_cur) == -1) { |
(void)sprintf(pathname, |
(void)sprintf(pathname, |
"getwd: Cannot stat \".\" (%s)", strerror(errno)); |
"getwd: Cannot stat \".\" (%s)", strerror(errno)); |
return NULL; |
return NULL; |
} |
} |
nextpathptr = strrcpy(nextpathptr, "../"); |
nextpathptr = strrcpy(nextpathptr, "../"); |
|
|
/* open the parent directory */ |
/* open the parent directory */ |
if (stat(nextpathptr, &st_dotdot) == -1) { |
if (stat(nextpathptr, &st_dotdot) == -1) { |
(void)sprintf(pathname, |
(void)sprintf(pathname, |
"getwd: Cannot stat directory \"%s\" (%s)", |
"getwd: Cannot stat directory \"%s\" (%s)", |
nextpathptr, strerror(errno)); |
nextpathptr, strerror(errno)); |
return NULL; |
return NULL; |
} |
} |
if ((dp = opendir(nextpathptr)) == NULL) { |
if ((dp = opendir(nextpathptr)) == NULL) { |
(void)sprintf(pathname, |
(void)sprintf(pathname, |
"getwd: Cannot open directory \"%s\" (%s)", |
"getwd: Cannot open directory \"%s\" (%s)", |
nextpathptr, strerror(errno)); |
nextpathptr, strerror(errno)); |
return NULL; |
return NULL; |
} |
} |
|
|
|
|
continue; |
continue; |
(void)strcpy(cur_name_add, d->d_name); |
(void)strcpy(cur_name_add, d->d_name); |
if (lstat(nextpathptr, &st_next) == -1) { |
if (lstat(nextpathptr, &st_next) == -1) { |
(void)sprintf(pathname, "getwd: Cannot stat \"%s\" (%s)", |
(void)sprintf(pathname, |
d->d_name, strerror(errno)); |
"getwd: Cannot stat \"%s\" (%s)", |
|
d->d_name, strerror(errno)); |
(void)closedir(dp); |
(void)closedir(dp); |
return NULL; |
return NULL; |
} |
} |
|
|
} |
} |
} |
} |
if (d == NULL) { |
if (d == NULL) { |
(void)sprintf(pathname, "getwd: Cannot find \".\" in \"..\""); |
(void)sprintf(pathname, |
|
"getwd: Cannot find \".\" in \"..\""); |
(void)closedir(dp); |
(void)closedir(dp); |
return NULL; |
return NULL; |
} |
} |