Patchwork [gccgo] Avoid producing // in an import file name

login
register
mail settings
Submitter Ian Taylor
Date Nov. 17, 2010, 10:45 p.m.
Message ID <mcr62vvy3gl.fsf@google.com>
Download mbox | patch
Permalink /patch/71629/
State New
Headers show

Comments

Ian Taylor - Nov. 17, 2010, 10:45 p.m.
This patch changes import to avoid producing // when concatenating a
directory from the search path and the file name.  This implements the
same algorithm as append_file_to_dir in libcpp/files.c.  Committed to
gccgo branch.

Ian

Patch

diff -r 33c42b414546 go/import.cc
--- a/go/import.cc	Wed Nov 17 14:33:26 2010 -0800
+++ b/go/import.cc	Wed Nov 17 14:43:18 2010 -0800
@@ -67,8 +67,11 @@ 
 	   p != search_path.end();
 	   ++p)
 	{
-	  Stream* s = Import::try_package_in_directory(*p + '/' + filename,
-						       location);
+	  std::string indir = *p;
+	  if (!indir.empty() && indir[indir.size() - 1] != '/')
+	    indir += '/';
+	  indir += filename;
+	  Stream* s = Import::try_package_in_directory(indir, location);
 	  if (s != NULL)
 	    return s;
 	}