* path.cc (realpath): Drop call to mount_info::conv_to_posix_path
in favor of calling path_conv with PC_POSIX flag. Align error handling closer to POSIX. As on Linux, return user space allocated memory if second parameter is NULL.
This commit is contained in:
parent
9d13e04523
commit
3716969169
@ -1,3 +1,10 @@
|
|||||||
|
2005-08-25 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
|
* path.cc (realpath): Drop call to mount_info::conv_to_posix_path
|
||||||
|
in favor of calling path_conv with PC_POSIX flag. Align error
|
||||||
|
handling closer to POSIX. As on Linux, return user space allocated
|
||||||
|
memory if second parameter is NULL.
|
||||||
|
|
||||||
2005-08-25 Corinna Vinschen <corinna@vinschen.de>
|
2005-08-25 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* path.cc (normalize_win32_path): Honor network paths. Fold more
|
* path.cc (normalize_win32_path): Honor network paths. Fold more
|
||||||
|
@ -3653,24 +3653,43 @@ extern "C" char *
|
|||||||
realpath (const char *path, char *resolved)
|
realpath (const char *path, char *resolved)
|
||||||
{
|
{
|
||||||
extern suffix_info stat_suffixes[];
|
extern suffix_info stat_suffixes[];
|
||||||
int err;
|
|
||||||
|
|
||||||
path_conv real_path (path, PC_SYM_FOLLOW, stat_suffixes);
|
/* Make sure the right errno is returned if path is NULL. */
|
||||||
|
if (!path)
|
||||||
if (real_path.error)
|
|
||||||
err = real_path.error;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
err = mount_table->conv_to_posix_path (real_path.get_win32 (), resolved, 0);
|
set_errno (EINVAL);
|
||||||
if (err == 0)
|
return NULL;
|
||||||
return resolved;
|
}
|
||||||
|
|
||||||
|
path_conv real_path (path, PC_SYM_FOLLOW | PC_POSIX, stat_suffixes);
|
||||||
|
|
||||||
|
/* Guard writing to a potentially invalid resolved. */
|
||||||
|
myfault efault;
|
||||||
|
if (efault.faulted (EFAULT))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* Linux has this funny non-standard extension. If "resolved" is NULL,
|
||||||
|
realpath mallocs the space by itself and returns it to the application.
|
||||||
|
The application is responsible for calling free() then. This extension
|
||||||
|
is backed by POSIX, which allows implementation-defined behaviour if
|
||||||
|
"resolved" is NULL. That's good enough for us to do the same here. */
|
||||||
|
|
||||||
|
if (!real_path.error && real_path.exists ())
|
||||||
|
{
|
||||||
|
if (!resolved)
|
||||||
|
{
|
||||||
|
resolved = (char *) malloc (strlen (real_path.normalized_path) + 1);
|
||||||
|
if (!resolved)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return strcpy (resolved, real_path.normalized_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: on error, we are supposed to put the name of the path
|
/* FIXME: on error, we are supposed to put the name of the path
|
||||||
component which could not be resolved into RESOLVED. */
|
component which could not be resolved into RESOLVED. */
|
||||||
resolved[0] = '\0';
|
if (resolved)
|
||||||
|
resolved[0] = '\0';
|
||||||
set_errno (err);
|
set_errno (real_path.error ?: ENOENT);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user