https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108350
--- Comment #19 from Bill Zissimopoulos <gnu.org at billz dot fastmail.fm> --- Comment on attachment 54264 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54264 patch Many thanks for the patch. Please consider the following: LINES 144-152: I would change the CreateFile call to look like: HANDLE fh = CreateFile ( filename ,FILE_READ_ATTRIBUTES ,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE ,NULL ,OPEN_EXISTING ,FILE_FLAG_BACKUP_SEMANTICS ,NULL ); - The FILE_READ_ATTRIBUTES is the only permission required here. (In fact 0 will work as well because CreateFile always adds FILE_READ_ATTRIBUTES.) There is no need to ask for extra permissions that the process may not have. - The FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE is something I do religiously. Although the use of FILE_SHARE_READ should be sufficient in your case according to documentation, I have found that there are some corner cases where the use of FILE_SHARE_* flags is not consistent with documentation. To avoid such cases I use the combo of the flags above. - The FILE_FLAG_BACKUP_SEMANTICS is needed if lrealpath is used on directories. LINE 152: I would fall back to the GetFullPathName method rather than using strdup here. LINE 192: There are actually two cases to consider regarding the \\?\ prefix: - Case \\?\X:\Path\To\File: you should make the conversion \\?\X:\Path\To\File -> X:\Path\To\File (as you are already doing). - Case \\?\UNC\Server\Share\Path\To\File: you should make the conversion \\?\UNC\Server\Share\Path\To\File -> \\Server\Share\Path\To\File