Patchwork [Ada] Fix Current_Directory behavior for root dirs on Windows

login
register
mail settings
Submitter Arnaud Charlet
Date March 9, 2012, 2:55 p.m.
Message ID <20120309145506.GA5793@adacore.com>
Download mbox | patch
Permalink /patch/145725/
State New
Headers show

Comments

Arnaud Charlet - March 9, 2012, 2:55 p.m.
Current_Directory incorrectly returned the path of the form "X:"
instead of "X:\"

Manually tested on i686-pc-mingw32.
Tested on x86_64-pc-linux-gnu, committed on trunk

2012-03-09  Vasiliy Fofanov  <fofanov@adacore.com>

	* a-direct.adb: Do not strip the trailing directory separator
	from path, as this is already done inside Normalize_Pathname;
	doing it again produces the wrong result on Windows for the
	drive's root dir (i.e. "X:\" becomes "X:").

Patch

Index: a-direct.adb
===================================================================
--- a-direct.adb	(revision 185136)
+++ a-direct.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2004-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 2004-2012, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -514,18 +514,10 @@ 
    begin
       Local_Get_Current_Dir (Buffer'Address, Path_Len'Address);
 
-      declare
-         --  We need to resolve links because of A.16(47), since we must not
-         --  return alternative names for files
-         Cur : constant String := Normalize_Pathname (Buffer (1 .. Path_Len));
+      --  We need to resolve links because of A.16(47), since we must not
+      --  return alternative names for files
+      return Normalize_Pathname (Buffer (1 .. Path_Len));
 
-      begin
-         if Cur'Length > 1 and then Cur (Cur'Last) = Dir_Separator then
-            return Cur (1 .. Cur'Last - 1);
-         else
-            return Cur;
-         end if;
-      end;
    end Current_Directory;
 
    ----------------------