https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=8b83da2d55b2a61f22b8b330f966d06e3092b079

commit 8b83da2d55b2a61f22b8b330f966d06e3092b079
Author: Corinna Vinschen <cori...@vinschen.de>
Date:   Tue Feb 9 15:00:30 2016 +0100

    cygwin_conv_path: Always preserve trailing backslashes in conversion to 
POSIX paths
    
        * include/sys/cygwin.h (CCP_CONVFLAGS_MASK): Define.
        * mount.h (__CCP_APP_SLASH): Define.
        * mount.cc (mount_info::conv_to_posix_path): Handle __CCP_APP_SLASH
        flag.
        * path.cc (cygwin_conv_path): Use CCP_CONVFLAGS_MASK to evaluate
        "how" flag values.  Always add __CCP_APP_SLASH flag when calling
        mount_info::conv_to_posix_path.
    
    Signed-off-by: Corinna Vinschen <cori...@vinschen.de>

Diff:
---
 winsup/cygwin/include/sys/cygwin.h | 4 +++-
 winsup/cygwin/mount.cc             | 3 ++-
 winsup/cygwin/mount.h              | 4 ++++
 winsup/cygwin/path.cc              | 6 +++---
 4 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/include/sys/cygwin.h 
b/winsup/cygwin/include/sys/cygwin.h
index 6c720e0..5b7da58 100644
--- a/winsup/cygwin/include/sys/cygwin.h
+++ b/winsup/cygwin/include/sys/cygwin.h
@@ -59,8 +59,10 @@ enum
   /* Or these values to the above as needed. */
   CCP_ABSOLUTE = 0,            /* Request absolute path (default).     */
   CCP_RELATIVE = 0x100,        /* Request to keep path relative.       */
-  CCP_PROC_CYGDRIVE = 0x200            /* Request to return /proc/cygdrive
+  CCP_PROC_CYGDRIVE = 0x200,           /* Request to return /proc/cygdrive
                                   path (only with CCP_*_TO_POSIX).   */
+
+  CCP_CONVFLAGS_MASK = 0x300,
 };
 typedef unsigned int cygwin_conv_path_t;
 
diff --git a/winsup/cygwin/mount.cc b/winsup/cygwin/mount.cc
index 569328f..961d34b 100644
--- a/winsup/cygwin/mount.cc
+++ b/winsup/cygwin/mount.cc
@@ -899,7 +899,8 @@ mount_info::conv_to_posix_path (const char *src_path, char 
*posix_path,
   else
     {
       const char *lastchar = src_path + src_path_len - 1;
-      append_slash = isdirsep (*lastchar) && lastchar[-1] != ':';
+      append_slash = isdirsep (*lastchar)
+                    && ((ccp_flags & __CCP_APP_SLASH) || lastchar[-1] != ':');
     }
 
   debug_printf ("conv_to_posix_path (%s, 0x%x, %s)", src_path, ccp_flags,
diff --git a/winsup/cygwin/mount.h b/winsup/cygwin/mount.h
index 172a0b0..7219461 100644
--- a/winsup/cygwin/mount.h
+++ b/winsup/cygwin/mount.h
@@ -12,6 +12,10 @@ details. */
 #ifndef _MOUNT_H
 #define _MOUNT_H
 
+#define __CCP_APP_SLASH        0x10000000      /* Internal flag for 
conv_to_posix_path.
+                                          always append slash, even if path
+                                          is "X:\\" only. */
+
 enum disk_type
 {
   DT_NODISK,
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index e49f180..20391bf 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3318,7 +3318,7 @@ cygwin_conv_path (cygwin_conv_path_t what, const void 
*from, void *to,
   char *buf = NULL;
   PWCHAR path = NULL;
   int error = 0;
-  int how = what & ~CCP_CONVTYPE_MASK;
+  int how = what & CCP_CONVFLAGS_MASK;
   what &= CCP_CONVTYPE_MASK;
   int ret = -1;
 
@@ -3444,7 +3444,7 @@ cygwin_conv_path (cygwin_conv_path_t what, const void 
*from, void *to,
        case CCP_WIN_A_TO_POSIX:
          buf = tp.c_get ();
          error = mount_table->conv_to_posix_path ((const char *) from, buf,
-                                                  how);
+                                                  how | __CCP_APP_SLASH);
          if (error)
            {
              set_errno (p.error);
@@ -3455,7 +3455,7 @@ cygwin_conv_path (cygwin_conv_path_t what, const void 
*from, void *to,
        case CCP_WIN_W_TO_POSIX:
          buf = tp.c_get ();
          error = mount_table->conv_to_posix_path ((const PWCHAR) from, buf,
-                                                  how);
+                                                  how | __CCP_APP_SLASH);
          if (error)
            {
              set_errno (error);

Reply via email to