From: corinna Date: Thu, 25 Aug 2005 21:18:21 +0000 (+0000) Subject: * path.cc (realpath): Drop call to mount_info::conv_to_posix_path X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=ca327ee72eae15d9147a1e55c9f000615324479b;p=pf3gnuchains%2Fpf3gnuchains3x.git * 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. --- diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index fce488b17b..cc988a0089 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,12 @@ 2005-08-25 Corinna Vinschen + * 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 + * path.cc (normalize_win32_path): Honor network paths. Fold more than two leading dir separators into one. Check for dir separator instead of just slashes to handle incoming Win32 paths correctly. diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc index 568072f4c8..d4640898dc 100644 --- a/winsup/cygwin/path.cc +++ b/winsup/cygwin/path.cc @@ -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); + /* Make sure the right errno is returned if path is NULL. */ + if (!path) + { + set_errno (EINVAL); + return NULL; + } - if (real_path.error) - err = real_path.error; - else + 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 ()) { - err = mount_table->conv_to_posix_path (real_path.get_win32 (), resolved, 0); - if (err == 0) - return resolved; + 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; }