fix bug where /dirname would return NULL
This commit is contained in:
11
realpath.c
11
realpath.c
@@ -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));
|
||||||
|
@@ -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));
|
||||||
|
Reference in New Issue
Block a user