This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch]: 3 or more initial slashes


POSIX specifies that three ore more slashes at the beginning
of a pathname are equivalent to a single one.
This patch implements that feature. 
Only Posix paths are affected, Windows paths are left alone. 
Also, Posix paths are never handled by normalize_win32_path
anymore.

Pierre

2004-04-20  Pierre Humblet <pierre.humblet@ieee.org>

	* path.cc (normalize_posix_path): Process all Posix paths and
	map three or more initial slashes to a single one. Simplify
	processing following two initial slashes. 
	(normalize_win32_path): Make last argument non-optional and
	do not check for NULL value.

Index: path.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/path.cc,v
retrieving revision 1.302
diff -u -p -r1.302 path.cc
--- path.cc     16 Apr 2004 21:22:13 -0000      1.302
+++ path.cc     20 Apr 2004 17:14:40 -0000
@@ -75,7 +75,7 @@ details. */
 #include "cygtls.h"
 #include <assert.h>
 
-static int normalize_win32_path (const char *src, char *dst, char ** tail = 0);
+static int normalize_win32_path (const char *src, char *dst, char ** tail);
 static void slashify (const char *src, char *dst, int trailing_slash_p);
 static void backslashify (const char *src, char *dst, int trailing_slash_p);
 
@@ -202,7 +202,7 @@ normalize_posix_path (const char *src, c
   const char *in_src = src;
   char *in_dst = dst;
 
-  if (isdrive (src) || slash_unc_prefix_p (src))
+  if (isdrive (src) || *src == '\\')
     goto win32_path;
 
   if (!isslash (src[0]))
@@ -220,26 +220,12 @@ normalize_posix_path (const char *src, c
        *dst++ = '/';
     }
   /* Two leading /'s?  If so, preserve them.  */
-  else if (isslash (src[1]))
+  else if (isslash (src[1]) && !isslash (src[2]))
     {
       *dst++ = '/';
       *dst++ = '/';
       src += 2;
-      if (isslash (*src))
-       { /* Starts with three or more slashes - reset. */
-         dst = dst_start;
-         *dst++ = '/';
-         src = src_start + 1;
-       }
-      else if (src[0] == '.' && isslash (src[1]))
-       {
-         *dst++ = '.';
-         *dst++ = '/';
-         src += 2;
-       }
     }
-  else
-    *dst = '\0';
 
   while (*src)
     {
@@ -1005,9 +991,8 @@ normalize_win32_path (const char *src, c
       if ((dst - dst_start) >= CYG_MAX_PATH)
        return ENAMETOOLONG;
     }
-  *dst = 0;
-  if (tail)
-    *tail = dst;
+  *dst = '\0';
+  *tail = dst;
   debug_printf ("%s = normalize_win32_path (%s)", dst_start, src_start);
   return 0;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]