public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR ada/111909 On Darwin, determine filesystem case sensitivity at runtime
@ 2023-10-29 11:51 Simon Wright
  2023-10-31  8:07 ` Iain Sandoe
  2023-11-03  8:39 ` Arnaud Charlet
  0 siblings, 2 replies; 30+ messages in thread
From: Simon Wright @ 2023-10-29 11:51 UTC (permalink / raw)
  To: gcc-patches

This change affects only Ada.

In gcc/ada/adaint.c(__gnat_get_file_names_case_sensitive), the
assumption for __APPLE__ is that file names are case-insensitive
unless __arm__ or __arm64__ are defined, in which case file names
are declared case-sensitive.

The associated comment is
  "By default, we suppose filesystems aren't case sensitive on
  Windows and Darwin (but they are on arm-darwin)."

This means that on aarch64-apple-darwin, file names are declared
case-sensitive, which is not normally the case (but users can set
up case-sensitive volumes).

It's understood that GCC does not currently support iOS/tvOS/watchOS,
so we assume macOS.

Bootstrapped on x86_64-apple-darwin with languages c,c++,ada and regression tested (check-gnat).
Also, tested with the example from PR ada/81114, extracted into 4 volumes (APFS, APFS-case-sensitive,
HFS, HFS-case-sensitive; the example code built successfully on the case-sensitive volumes.
Setting GNAT_FILE_NAME_CASE_SENSITIVE successfully overrode the choices made by the
new code.

 gcc/ada/Changelog:

 2023-10-29 Simon Wright <simon@pushface.org>

 PR ada/111909

 * gcc/ada/adaint.c
  (__gnat_get_file_names_case_sensitive): Remove the checks for
  __arm__, __arm64__.
  Split out the check for __APPLE__; remove the checks for __arm__,
  __arm64__, and use getattrlist(2) to determine whether the current
  working directory is on a case-sensitive filesystem.

Signed-off-by: Simon Wright <simon@pushface.org>
---
 gcc/ada/adaint.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/adaint.c b/gcc/ada/adaint.c
index 2a193efc002..43d166824b0 100644
--- a/gcc/ada/adaint.c
+++ b/gcc/ada/adaint.c
@@ -85,6 +85,7 @@
 
 #if defined (__APPLE__)
 #include <unistd.h>
+#include <sys/attr.h>
 #endif
 
 #if defined (__hpux__)
@@ -613,11 +614,48 @@ __gnat_get_file_names_case_sensitive (void)
       else
 	{
 	  /* By default, we suppose filesystems aren't case sensitive on
-	     Windows and Darwin (but they are on arm-darwin).  */
-#if defined (WINNT) || defined (__DJGPP__) \
-  || (defined (__APPLE__) && !(defined (__arm__) || defined (__arm64__)))
+	     Windows or DOS.  */
+#if defined (WINNT) || defined (__DJGPP__)
 	  file_names_case_sensitive_cache = 0;
-#else
+#elif defined (__APPLE__)
+	  /* Determine whether the current volume is case-sensitive.  */
+	  {
+	    /* Formulate a query for the volume capabilities.  */
+	    struct attrlist attrList
+	      = {ATTR_BIT_MAP_COUNT,
+		 0,				      /* reserved.  */
+		 0,				      /* commonattr.  */
+		 ATTR_VOL_INFO | ATTR_VOL_CAPABILITIES, /* volattr.  */
+		 0,				      /* dirattr.  */
+		 0,				      /* fileattr.  */
+		 0				      /* forkattr.  */
+		};
+
+	    /* A buffer to contain just the volume capabilities.  */
+	    struct returnBuf {
+	      u_int32_t length;
+	      vol_capabilities_attr_t caps;
+	    } __attribute__ ((aligned (4), packed)) retBuf;
+
+	    /* Default to case-insensitive.  */
+	    file_names_case_sensitive_cache = 0;
+
+	    /* Query the current working directory.  */
+	    if (getattrlist (".",
+			     &attrList,
+			     &retBuf,
+			     sizeof (retBuf),
+			     0) == 0)
+	      /* The call succeeded.  */
+	      if ((retBuf.caps.valid[VOL_CAPABILITIES_FORMAT]
+		   & VOL_CAP_FMT_CASE_SENSITIVE))
+		/* The volume could be case-sensitive.  */
+		if (retBuf.caps.capabilities[VOL_CAPABILITIES_FORMAT]
+		    & VOL_CAP_FMT_CASE_SENSITIVE)
+		  /* The volume is case-sensitive.  */
+		  file_names_case_sensitive_cache = 1;
+	  }
+#else /* Neither Windows nor Apple.  */
 	  file_names_case_sensitive_cache = 1;
 #endif
 	}
-- 
2.39.3 (Apple Git-145)


^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2023-11-28 16:49 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-29 11:51 [PATCH] Fix PR ada/111909 On Darwin, determine filesystem case sensitivity at runtime Simon Wright
2023-10-31  8:07 ` Iain Sandoe
2023-11-03  8:39 ` Arnaud Charlet
2023-11-04 17:02   ` Simon Wright
2023-11-04 23:28     ` Iain Sandoe
2023-11-06  8:36     ` Arnaud Charlet
2023-11-11 17:47       ` Simon Wright
2023-11-11 18:10         ` Iain Sandoe
2023-11-13 16:03           ` Simon Wright
2023-11-13 16:18             ` Arnaud Charlet
2023-11-16 20:56               ` Simon Wright
2023-11-17  8:37                 ` Arnaud Charlet
2023-11-17  9:06                   ` Simon Wright
2023-11-17  9:29                     ` Arnaud Charlet
2023-11-17 12:53                       ` Simon Wright
2023-11-17 13:36                         ` Arnaud Charlet
2023-11-17 13:39                           ` Arnaud Charlet
2023-11-17 13:43                           ` Simon Wright
2023-11-21 11:22                             ` Iain Sandoe
2023-11-21 20:25                               ` Simon Wright
2023-11-21 23:13                                 ` Iain Sandoe
2023-11-22 13:54                                   ` Simon Wright
2023-11-22 13:55                                     ` Arnaud Charlet
2023-11-22 14:48                                       ` Iain Sandoe
2023-11-22 15:03                                         ` Iain Sandoe
2023-11-22 15:13                                           ` Simon Wright
2023-11-28 12:16                                             ` Simon Wright
2023-11-28 13:50                                               ` Marc Poulhiès
2023-11-28 16:48                                                 ` Marc Poulhiès
2023-11-22 14:41                                     ` Paul Koning

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).