fix bug where /dirname would return NULL

This commit is contained in:
Todd C. Miller
1994-06-07 23:21:23 +00:00
parent c2c72c6e73
commit d8013e48bb
2 changed files with 18 additions and 4 deletions

View File

@@ -163,12 +163,19 @@ char * realpath(old, new)
errno = ENOTDIR; errno = ENOTDIR;
return(realpath_ret(NULL, cwd)); return(realpath_ret(NULL, cwd));
} }
*(temp++) = '\0'; *(temp++) = '\0';
(void) strcpy(buf, temp); (void) strcpy(buf, temp);
/* if the last '/' is the first char in new we need to preserve it */
if (new[0] == '\0') {
new[0] = '/';
new[1] = '\0';
}
/* /*
* chdir() to new and go a getcwd() to find real path * chdir() to new and go a getcwd() to find real path then
* then append buf (last component of the path) and return. * append buf * (last component of the path) and return.
*/ */
if (chdir(new)) if (chdir(new))
return(realpath_ret(NULL, cwd)); return(realpath_ret(NULL, cwd));

View File

@@ -163,12 +163,19 @@ char * realpath(old, new)
errno = ENOTDIR; errno = ENOTDIR;
return(realpath_ret(NULL, cwd)); return(realpath_ret(NULL, cwd));
} }
*(temp++) = '\0'; *(temp++) = '\0';
(void) strcpy(buf, temp); (void) strcpy(buf, temp);
/* if the last '/' is the first char in new we need to preserve it */
if (new[0] == '\0') {
new[0] = '/';
new[1] = '\0';
}
/* /*
* chdir() to new and go a getcwd() to find real path * chdir() to new and go a getcwd() to find real path then
* then append buf (last component of the path) and return. * append buf * (last component of the path) and return.
*/ */
if (chdir(new)) if (chdir(new))
return(realpath_ret(NULL, cwd)); return(realpath_ret(NULL, cwd));