Skip to content

Commit c273e01

Browse files
committed
Merge branch 'fixes-for-msys2'
We deviated a bit too much from MSYS2's patches, by amending them... Let's put our fixes on top, maybe the MSYS2 maintainer will be in a more collaborative and communicative mood and we might get them integrated, at long last. Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 1907824 + 1bfa869 commit c273e01

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

winsup/cygwin/msys2_path_conv.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ void posix_to_win32_path(const char* from, const char* to, char** dst, const cha
624624
strncpy(one_path, from, to-from);
625625
one_path[to-from] = '\0';
626626

627-
path_conv conv (one_path, 0);
627+
path_conv conv (one_path, PC_KEEP_FINAL_SLASH);
628628
if (conv.error)
629629
{
630630
set_errno(conv.error);

winsup/cygwin/path.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,22 @@ path_conv::check (const char *src, unsigned opt,
12541254
cfree (wide_path);
12551255
wide_path = NULL;
12561256
}
1257+
1258+
if (need_directory)
1259+
{
1260+
size_t n = strlen (this->path);
1261+
/* Do not add trailing \ to UNC device names like \\.\a: */
1262+
if (this->path[n - 1] != '\\' &&
1263+
(strncmp (this->path, "\\\\.\\", 4) != 0))
1264+
{
1265+
this->modifiable_path ()[n] = '\\';
1266+
this->modifiable_path ()[n + 1] = '\0';
1267+
}
1268+
need_directory = 0;
1269+
}
12571270
}
12581271

1259-
if (need_directory)
1272+
if ((opt & PC_KEEP_FINAL_SLASH) && need_directory)
12601273
{
12611274
size_t n = strlen (this->path);
12621275
/* Do not add trailing \ to UNC device names like \\.\a: */
@@ -1266,6 +1279,7 @@ path_conv::check (const char *src, unsigned opt,
12661279
this->modifiable_path ()[n] = '\\';
12671280
this->modifiable_path ()[n + 1] = '\0';
12681281
}
1282+
need_directory = 0;
12691283
}
12701284

12711285
if (opt & PC_OPEN)

winsup/cygwin/path.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum pathconv_arg
5959
PC_KEEP_HANDLE = _BIT (12), /* keep handle for later stat calls */
6060
PC_NO_ACCESS_CHECK = _BIT (13), /* helper flag for error check */
6161
PC_SYM_NOFOLLOW_DIR = _BIT (14), /* don't follow a trailing slash */
62+
PC_KEEP_FINAL_SLASH = _BIT (15), /* do not remove a trailing slash */
6263
PC_DONT_USE = _BIT (31) /* conversion to signed happens. */
6364
};
6465

0 commit comments

Comments
 (0)