]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
windows-cygpath: Handle UNC file names on Cygwin correctly.
authorBruno Haible <bruno@clisp.org>
Tue, 28 Apr 2026 14:49:45 +0000 (16:49 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 28 Apr 2026 14:51:06 +0000 (16:51 +0200)
Reported and initial patch by Vaclav Slavik <vaclav@slavik.io> in
<https://savannah.gnu.org/bugs/?68291>.

* lib/windows-cygpath.c (windows_cygpath_w): Treat file names that start
with '//' like absolute native Windows file names.

ChangeLog
lib/windows-cygpath.c

index 8d9da78d4694b5de50f9e7d7969726eb82c1a0fb..a2bca1ce9892fb9eca424ce41694907d81e3b800 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2026-04-28  Bruno Haible  <bruno@clisp.org>
+
+       windows-cygpath: Handle UNC file names on Cygwin correctly.
+       Reported and initial patch by Vaclav Slavik <vaclav@slavik.io> in
+       <https://savannah.gnu.org/bugs/?68291>.
+       * lib/windows-cygpath.c (windows_cygpath_w): Treat file names that start
+       with '//' like absolute native Windows file names.
+
 2026-04-28  Bruno Haible  <bruno@clisp.org>
 
        idx: Remove redundant #include.
index 11cc9a65a9447ad3d92d1b17e51e65555c3aa853..8cb34d48b7acc4a287a6fcece69666d03081e396 100644 (file)
@@ -98,9 +98,9 @@ execute_and_read_line (const char *progname,
 char *
 windows_cygpath_w (const char *filename)
 {
-  if (filename[0] == '/')
+  if (filename[0] == '/' && filename[1] != '/')
     {
-      /* It's an absolute POSIX-style file name.  */
+      /* It's an absolute POSIX-style file name, e.g. '/path/to/file'.  */
       const char *argv[4];
       argv[0] = "cygpath";
       argv[1] = "-w";
@@ -114,9 +114,14 @@ windows_cygpath_w (const char *filename)
     }
   else
     {
-      /* It's a relative file name, or an absolute native Windows file name.
+      /* It's a relative file name, or either
+         an absolute native Windows file name (e.g. 'C:/path/to/file') or
+         a native Windows UNC file name ('//server/share/path/to/file'), see
+         <https://cygwin.com/cygwin-ug-net/using.html#unc-paths> and
+         <https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file>.
          All we need to do is to convert slashes to backslahes, e.g.
-         'C:/Users' -> 'C:\Users'.  */
+         'C:/Users'                    -> 'C:\Users'
+         '//server/share/path/to/file' -> '\\server\share\path\to\file'.  */
       size_t len = strlen (filename) + 1;
       char *copy = XNMALLOC (len, char);
       for (size_t i = 0; i < len; i++)