* 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:
Corinna Vinschen 2005-08-25 21:18:26 +00:00
parent 9d13e04523
commit 3716969169
2 changed files with 38 additions and 12 deletions

View File

@ -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>
* path.cc (normalize_win32_path): Honor network paths. Fold more

View File

@ -3653,24 +3653,43 @@ extern "C" char *
realpath (const char *path, char *resolved)
{
extern suffix_info stat_suffixes[];
int err;
path_conv real_path (path, PC_SYM_FOLLOW, stat_suffixes);
if (real_path.error)
err = real_path.error;
else
/* Make sure the right errno is returned if path is NULL. */
if (!path)
{
err = mount_table->conv_to_posix_path (real_path.get_win32 (), resolved, 0);
if (err == 0)
return resolved;
set_errno (EINVAL);
return NULL;
}
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
component which could not be resolved into RESOLVED. */
resolved[0] = '\0';
set_errno (err);
if (resolved)
resolved[0] = '\0';
set_errno (real_path.error ?: ENOENT);
return NULL;
}