diff options
author | Ciaran Woodward <ciaranwoodward@xmos.com> | 2025-02-12 17:57:32 +0000 |
---|---|---|
committer | Ciaran Woodward <ciaranwoodward@xmos.com> | 2025-02-25 14:58:15 +0000 |
commit | f2cc668e2b0c75d8baaf1b754d9a311084508db3 (patch) | |
tree | a49321c844211bcfa8c1a36a232defdbc7fe8306 | |
parent | 6693696a7dac44f2f80e89d2d0c4bebfb4543b59 (diff) | |
download | binutils-f2cc668e2b0c75d8baaf1b754d9a311084508db3.zip binutils-f2cc668e2b0c75d8baaf1b754d9a311084508db3.tar.gz binutils-f2cc668e2b0c75d8baaf1b754d9a311084508db3.tar.bz2 |
Fix mkdir_recursive on windows when CWD is root
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>
-rw-r--r-- | gdbsupport/filestuff.cc | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/gdbsupport/filestuff.cc b/gdbsupport/filestuff.cc index 9e07af2..eb3b3c0 100644 --- a/gdbsupport/filestuff.cc +++ b/gdbsupport/filestuff.cc @@ -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. */ |