https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104421

            Bug ID: 104421
           Summary: The Ada.Directories.Modification_Time procedure does
                    not work for non-ASCII filenames in the Windows
                    environment.
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yeongtaek.ham at gmail dot com
  Target Milestone: ---

The Ada.Directories.Modification_Time procedure does not work for non-ASCII
filenames in the Windows environment.

Example code (file is UTF-8 encoded):
--------------------------------------------------------------------------------
with Ada.Calendar;
with Ada.Directories;
with Ada.Text_IO;
with GNAT.Calendar.Time_IO;

procedure Main is
   package TEXT_IO renames Ada.Text_IO;
   package TIME_IO renames GNAT.Calendar.Time_IO;

   Mod_Time : Ada.Calendar.Time;
begin
   TEXT_IO.Put_Line ("한글 출력");

   -- Good
   Mod_Time := Ada.Directories.Modification_Time("modtime.gpr");
   TIME_IO.Put_Time (Mod_Time, TIME_IO.ISO_Time);
   TEXT_IO.NEW_LINE;

   -- Error
   Mod_Time := Ada.Directories.Modification_Time("한글.txt");
   TIME_IO.Put_Time (Mod_Time, TIME_IO.ISO_Time);
   TEXT_IO.NEW_LINE;
end Main;
--------------------------------------------------------------------------------


Execution result:
--------------------------------------------------------------------------------
PS C:\Users\Regentag\desktop\AdaDev\FileModTime> chcp 65001
Active code page: 65001
PS C:\Users\Regentag\desktop\AdaDev\FileModTime> dir


    디렉터리: C:\Users\Regentag\desktop\AdaDev\FileModTime


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----          22-02-07     22:46                obj
d-----          22-02-07     21:02                src
-a----          22-02-07     19:30            126 modtime.gpr
-a----          22-02-07     19:30            126 한글.txt                        


PS C:\Users\Regentag\desktop\AdaDev\FileModTime> C:\GNAT\2021\bin\gprbuild.exe
.\modtime.gpr
Compile
   [Ada]          main.adb
Bind
   [gprbind]      main.bexch
   [Ada]          main.ali
Link
   [link]         main.adb
PS C:\Users\Regentag\desktop\AdaDev\FileModTime> .\obj\main.exe
한글 출력
2022-02-07T19:30:02+09

raised ADA.IO_EXCEPTIONS.USE_ERROR : Unable to get modification time of the
file "한글.txt"
PS C:\Users\Regentag\desktop\AdaDev\FileModTime>
--------------------------------------------------------------------------------


My GCC version info:
--------------------------------------------------------------------------------
PS C:\GNAT\2021\bin> ./gcc -v
Using built-in specs.
COLLECT_GCC=C:\GNAT\2021\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../src/configure --enable-languages=ada,c,c++
--enable-checking=release --enable-threads=win32 --enable-libstdcxx-threads
--enable-lto --enable-large-address-aware
--with-bugurl=URL:mailto:rep...@adacore.com --disable-nls
--without-libiconv-prefix --disable-libstdcxx-pch --disable-libada
--disable-multilib --enable-libstdcxx
--with-mpfr=/it/sbx/a2c2/x86_64-windows64/mpfr-3.1.5/install
--with-gmp=/it/sbx/a2c2/x86_64-windows64/gmp-6.1.2/install
--with-mpc=/it/sbx/a2c2/x86_64-windows64/mpc-1.0.3/install
--with-build-time-tools=/it/sbx/a2c2/x86_64-windows64/gcc-c/build/buildtools/bin
--prefix=/it/sbx/a2c2/x86_64-windows64/gcc-c/pkg --build=x86_64-w64-mingw32
Thread model: win32
Supported LTO compression algorithms: zlib
gcc version 10.3.1 20210520 (for GNAT Community 2021 20210519) (GCC)
PS C:\GNAT\2021\bin>
--------------------------------------------------------------------------------


In my opinion, the cause is the use of the GetFileAttributesExA() function
without proper handling of the file name in the __gnat_file_time() function
implemented in adaint.c.
 *
https://github.com/gcc-mirror/gcc/blob/db95441cf5399aabc46ca83df19f7290c3e23cb1/gcc/ada/adaint.c#L1515

Reply via email to