]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix mkdir_recursive on windows when CWD is root
authorCiaran Woodward <ciaranwoodward@xmos.com>
Wed, 12 Feb 2025 17:57:32 +0000 (17:57 +0000)
committerCiaran Woodward <ciaranwoodward@xmos.com>
Tue, 25 Feb 2025 14:58:15 +0000 (14:58 +0000)
On windows, when creating a directory with an absolute path,
mkdir_recursive would start by trying to make 'C:'.

On windows, this has a special meaning, which is "the current
directory on the C drive". So the first thing it tries to do
is create the current directory.

Most of the time, this fails with EEXIST, so the function
continues as expected. However if the current directory is
C:/, trying to create that causes EPERM, which causes the
function to prematurely terminate.

(The same applies for any drive letter.)

This patch resolves this issue, by skipping the drive letter
so that it is never sent to the mkdir call.

Approved-By: Tom Tromey <tom@tromey.com>
gdbsupport/filestuff.cc

index 9e07af28dc2db5975776763376d567c51de6376c..eb3b3c0aade116f73e90801f85d1f09ae3a60f5b 100644 (file)
@@ -465,6 +465,13 @@ mkdir_recursive (const char *dir)
   char *component_start = start;
   char *component_end = start;
 
+#ifdef WIN32
+  /* If we're making an absolute path on windows, need to skip the drive
+     letter, which is the form 'C:/'.  */
+  if (dir[0] != '\0' && dir[1] == ':' && dir[2] == '/')
+    component_start += 3;
+#endif
+
   while (1)
     {
       /* Find the beginning of the next component.  */