OSDN Git Service

* path.cc (realpath): Drop call to mount_info::conv_to_posix_path
authorcorinna <corinna>
Thu, 25 Aug 2005 21:18:21 +0000 (21:18 +0000)
committercorinna <corinna>
Thu, 25 Aug 2005 21:18:21 +0000 (21:18 +0000)
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.

winsup/cygwin/ChangeLog
winsup/cygwin/path.cc

index fce488b..cc988a0 100644 (file)
@@ -1,5 +1,12 @@
 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
        than two leading dir separators into one.  Check for dir separator
        instead of just slashes to handle incoming Win32 paths correctly.
index 568072f..d464089 100644 (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);
+  /* 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;
 }