]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Fix Ada.Directories.Modification_Time on Windows
authorRonan Desplanques <desplanques@adacore.com>
Mon, 16 Oct 2023 15:09:25 +0000 (17:09 +0200)
committerMarc Poulhiès <poulhies@adacore.com>
Tue, 7 Nov 2023 09:15:04 +0000 (10:15 +0100)
Before this patch, Ada.Directories.Modification_Time called
GetFileAttributesExA under the hood on Windows. That would sometimes
fail to work with files whose names were non-ASCII.

This patch replaces the call to GetFileAttributesExA with a call to
GetFileAttributesEx preceded by an encoding scheme conversion, as is
done in other functions of the run-time library. This fixes the issues
that were observed with the previous implementations.

gcc/ada/

* adaint.c (__gnat_file_time): Fix Windows version.

gcc/ada/adaint.c

index 2a193efc0020e550e9be6d411cd3faed589915ce..bb4ed2607e50c382185540321de1f1578b617bc7 100644 (file)
@@ -1507,7 +1507,16 @@ extern long long __gnat_file_time(char* name)
     long long ll_time;
   } t_write;
 
-  if (!GetFileAttributesExA(name, GetFileExInfoStandard, &fad)) {
+  TCHAR wname [GNAT_MAX_PATH_LEN + 2];
+  int name_len;
+
+  S2WSC (wname, name, GNAT_MAX_PATH_LEN + 2);
+  name_len = _tcslen (wname);
+
+  if (name_len > GNAT_MAX_PATH_LEN)
+    return LLONG_MIN;
+
+  if (!GetFileAttributesEx(wname, GetFileExInfoStandard, &fad)) {
     return LLONG_MIN;
   }