Commit f33abf26 by Robert Dewar Committed by Arnaud Charlet

s-fileio.adb (Open): Normalize file name to lower case in non-case sensitive…

s-fileio.adb (Open): Normalize file name to lower case in non-case sensitive file name systems to...

2007-08-31  Robert Dewar  <dewar@adacore.com>

	* s-fileio.adb (Open): Normalize file name to lower case in non-case
	sensitive file name systems to avoid unexpected mismatch in Vista.

From-SVN: r127981
parent 9c510803
...@@ -34,8 +34,11 @@ ...@@ -34,8 +34,11 @@
with Ada.Finalization; use Ada.Finalization; with Ada.Finalization; use Ada.Finalization;
with Ada.IO_Exceptions; use Ada.IO_Exceptions; with Ada.IO_Exceptions; use Ada.IO_Exceptions;
with Interfaces.C_Streams; use Interfaces.C_Streams; with Interfaces.C_Streams; use Interfaces.C_Streams;
with System.CRTL; with System.CRTL;
with System.Case_Util; use System.Case_Util;
with System.Soft_Links; with System.Soft_Links;
with Ada.Unchecked_Deallocation; with Ada.Unchecked_Deallocation;
package body System.File_IO is package body System.File_IO is
...@@ -91,6 +94,14 @@ package body System.File_IO is ...@@ -91,6 +94,14 @@ package body System.File_IO is
(C, text_translation_required, "__gnat_text_translation_required"); (C, text_translation_required, "__gnat_text_translation_required");
-- If true, add appropriate suffix to control string for Open -- If true, add appropriate suffix to control string for Open
function Get_Case_Sensitive return Integer;
pragma Import (C, Get_Case_Sensitive,
"__gnat_get_file_names_case_sensitive");
File_Names_Case_Sensitive : constant Boolean := Get_Case_Sensitive /= 0;
-- Set to indicate whether the operating system convention is for file
-- names to be case sensitive (e.g., in Unix, set True), or non case
-- sensitive (e.g., in OS/2, set False).
----------------------- -----------------------
-- Local Subprograms -- -- Local Subprograms --
----------------------- -----------------------
...@@ -870,6 +881,17 @@ package body System.File_IO is ...@@ -870,6 +881,17 @@ package body System.File_IO is
Full_Name_Len := Full_Name_Len + 1; Full_Name_Len := Full_Name_Len + 1;
end loop; end loop;
-- Fullname is generated by calling system's full_name. The problem
-- is, full_name does nothing about the casing, so a file name
-- comparison may generally speaking not be valid on non-case
-- sensitive systems, and in particular we get unexpected failures
-- on Windows/Vista because of this. So we use s-casuti to force
-- the name to lower case.
if not File_Names_Case_Sensitive then
To_Lower (Fullname (1 .. Full_Name_Len));
end if;
-- If Shared=None or Shared=Yes, then check for the existence -- If Shared=None or Shared=Yes, then check for the existence
-- of another file with exactly the same full name. -- of another file with exactly the same full name.
...@@ -889,9 +911,9 @@ package body System.File_IO is ...@@ -889,9 +911,9 @@ package body System.File_IO is
if Fullname (1 .. Full_Name_Len) = P.Name.all then if Fullname (1 .. Full_Name_Len) = P.Name.all then
-- If we get a match, and either file has Shared=None, -- If we get a match, and either file has Shared=None,
-- then raise Use_Error, since we don't allow two -- then raise Use_Error, since we don't allow two files
-- files of the same name to be opened unless they -- of the same name to be opened unless they specify the
-- specify the required sharing mode. -- required sharing mode.
if Shared = None if Shared = None
or else P.Shared_Status = None or else P.Shared_Status = None
...@@ -907,13 +929,12 @@ package body System.File_IO is ...@@ -907,13 +929,12 @@ package body System.File_IO is
Stream := P.Stream; Stream := P.Stream;
exit; exit;
-- Otherwise one of the files has Shared=Yes and one -- Otherwise one of the files has Shared=Yes and one has
-- has Shared=No. If the current file has Shared=No -- Shared=No. If the current file has Shared=No then all
-- then all is well but we don't want to share any -- is well but we don't want to share any other file's
-- other file's stream. If the current file has -- stream. If the current file has Shared=Yes, we would
-- Shared=Yes, we would like to share a stream, but -- like to share a stream, but not from a file that has
-- not from a file that has Shared=No, so in either -- Shared=No, so either way, we just continue the search.
-- case we just keep going on the search.
else else
null; null;
...@@ -937,10 +958,9 @@ package body System.File_IO is ...@@ -937,10 +958,9 @@ package body System.File_IO is
if Stream = NULL_Stream then if Stream = NULL_Stream then
Fopen_Mode (Mode, Text, Creat, Amethod, Fopstr); Fopen_Mode (Mode, Text, Creat, Amethod, Fopstr);
-- A special case, if we are opening (OPEN case) a file and -- A special case, if we are opening (OPEN case) a file and the
-- the mode returned by Fopen_Mode is not "r" or "r+", then -- mode returned by Fopen_Mode is not "r" or "r+", then we first
-- we first make sure that the file exists as required by -- make sure that the file exists as required by Ada semantics.
-- Ada semantics.
if Creat = False and then Fopstr (1) /= 'r' then if Creat = False and then Fopstr (1) /= 'r' then
if file_exists (Namestr'Address) = 0 then if file_exists (Namestr'Address) = 0 then
...@@ -948,17 +968,15 @@ package body System.File_IO is ...@@ -948,17 +968,15 @@ package body System.File_IO is
end if; end if;
end if; end if;
-- Now open the file. Note that we use the name as given -- Now open the file. Note that we use the name as given in the
-- in the original Open call for this purpose, since that -- original Open call for this purpose, since that seems the
-- seems the clearest implementation of the intent. It -- clearest implementation of the intent. It would presumably
-- would presumably work to use the full name here, but -- work to use the full name here, but if there is any difference,
-- if there is any difference, then we should use the -- then we should use the name used in the call.
-- name used in the call.
-- Note: for a corresponding delete, we will use the full name,
-- Note: for a corresponding delete, we will use the -- since by the time of the delete, the current working directory
-- full name, since by the time of the delete, the -- may have changed and we do not want to delete a different file!
-- current working directory may have changed and
-- we do not want to delete a different file!
Stream := fopen (Namestr'Address, Fopstr'Address, Encoding); Stream := fopen (Namestr'Address, Fopstr'Address, Encoding);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment