On Fri, 8 Aug 2025, Brian Inglis via Cygwin wrote: > On 2025-08-08 00:53, Thomas Wolff via Cygwin wrote: > > Am 08.08.2025 um 02:31 schrieb Jeremy Drake via Cygwin: > >> On a case-insensitive but case-preserving filesystem, is there a Cygwin > >> API to get the on-disk case for a given path? It seems like `realpath` > >> ought to do it but running > >> $ touch case-test > >> $ realpath CASE-TEST > >> returns CASE-TEST. > > On the command line, you could use > > ls | grep -i > > > >> Regardless, canonicalize_file_name or realpath may not > >> be what I want because it would dereference symlinks. > >> > >> Background: I'm trying to debug some test failures in Clang, due to a > >> warning that's supposed to be issued when you #include "foo.h" but the > >> file on disk that it opened is "Foo.h". > > Looks like if you use wildcards, it should work correctly: > > $ lsattr -dl . > . --- > $ l *_exit* > _Exit.2 _exit.3 > $ l _exit.? > _Exit.2 _exit.3 > $ l _exit.[23] > _Exit.2 _exit.3 > $ l *EXIT-TEST* > exit-test > $ l *exit* > _Exit.2 _exit.3 EXIT exit-test > > also, you could just opendir(3)/readdir(3)/closedir(3) and strcasecmp(3). >
Yeah, globbing is opendir/readdir/closedir, but it'd have to be done on each path component to recover the on-disk case for a path. I'll explain now that I have a better idea what clang is doing under the hood. llvm has an API that opens a file with an out parameter for the "real" path. On Windows, it uses GetFinalPathNameByHandleW (FILE_NAME_NORMALIZED|VOLUME_NAME_DOS), with some massaging for UNC. On Unix, it first would prefer fcntl with F_GETPATH. It doesn't look like Cygwin provides that. If that's not available, available, it tries readlink on /proc/self/fd/%d. If that's not available, it falls back to realpath on the name input. I had a breakpoint on realpath that was not hit, so it appears that readlink is what it's doing. -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple