diff --git a/newlib/libc/stdlib/mbtowc_r.c b/newlib/libc/stdlib/mbtowc_r.c index ca876f9a02..ee43736378 100644 --- a/newlib/libc/stdlib/mbtowc_r.c +++ b/newlib/libc/stdlib/mbtowc_r.c @@ -36,7 +36,7 @@ __ascii_mbtowc (struct _reent *r, if (n == 0) return -2; -#ifdef __CYGWIN__ +#ifdef STRICTLY_7BIT_ASCII if ((wchar_t)*t >= 0x80) { _REENT_ERRNO(r) = EILSEQ; diff --git a/newlib/libc/stdlib/wctomb_r.c b/newlib/libc/stdlib/wctomb_r.c index a7f87cd9e2..2c536cec0e 100644 --- a/newlib/libc/stdlib/wctomb_r.c +++ b/newlib/libc/stdlib/wctomb_r.c @@ -29,7 +29,7 @@ __ascii_wctomb (struct _reent *r, if (s == NULL) return 0; -#ifdef __CYGWIN__ +#ifdef STRICTLY_7BIT_ASCII if ((size_t)wchar >= 0x80) #else if ((size_t)wchar >= 0x100) diff --git a/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt b/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt index 61e91c88d5..953d375864 100644 --- a/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt +++ b/winsup/cygwin/DevDocs/how-to-debug-cygwin.txt @@ -126,3 +126,9 @@ set CYGWIN_DEBUG=cat.exe:gdb.exe program will crash, probably in small_printf. At that point, a 'bt' command should show you the offending call to strace_printf with the improper format string. + +9. Debug output without strace + + If you cannot use gdb, or if the program behaves differently using strace + for whatever reason, you can still use the small_printf() function to + output debugging messages directly to stderr. diff --git a/winsup/cygwin/msys2_path_conv.cc b/winsup/cygwin/msys2_path_conv.cc index 5c592919da..133939a7a8 100644 --- a/winsup/cygwin/msys2_path_conv.cc +++ b/winsup/cygwin/msys2_path_conv.cc @@ -341,7 +341,64 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (*it == '\0' || it == end) return NONE; - while (!isalnum(*it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { + /* Let's not convert ~/.file to ~C:\msys64\.file */ + if (*it == '~') { +skip_p2w: + *src = end; + return NONE; + } + + /* + * Skip path mangling when environment indicates it. + */ + const char *no_pathconv = getenv ("MSYS_NO_PATHCONV"); + + if (no_pathconv) + goto skip_p2w; + + /* + * Prevent Git's :file.txt and :/message syntax from beeing modified. + */ + if (*it == ':') + goto skip_p2w; + + while (it != end && *it) { + switch (*it) { + case '`': + case '\'': + case '"': + case '*': + case '?': + case '[': + case ']': + goto skip_p2w; + case '/': + if (it + 1 < end && it[1] == '~') + goto skip_p2w; + break; + case ':': + // Avoid mangling IPv6 addresses + if (it + 1 < end && it[1] == ':') + goto skip_p2w; + + // Leave Git's :./name syntax alone + if (it + 1 < end && it[1] == '.') { + if (it + 2 < end && it[2] == '/') + goto skip_p2w; + if (it + 3 < end && it[2] == '.' && it[3] == '/') + goto skip_p2w; + } + break; + case '@': + // Paths do not contain '@@' + if (it + 1 < end && it[1] == '@') + goto skip_p2w; + } + ++it; + } + it = *src; + + while (!isalnum(*it) && !(0x80 & *it) && *it != '/' && *it != '\\' && *it != ':' && *it != '-' && *it != '.') { recurse = true; it = ++*src; if (it == end || *it == '\0') return NONE; @@ -413,6 +470,8 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en int starts_with_minus = 0; int starts_with_minus_alpha = 0; + int only_dots = *it == '.'; + int has_slashes = 0; if (*it == '-') { starts_with_minus = 1; it += 1; @@ -456,11 +515,17 @@ path_type find_path_start_and_type(const char** src, int recurse, const char* en if (ch == '/' && *(it2 + 1) == '/') { return URL; } else { + if (!only_dots && !has_slashes) + goto skip_p2w; return POSIX_PATH_LIST; } } else if (memchr(it2, '=', end - it2) == NULL) { return SIMPLE_WINDOWS_PATH; } + } else if (ch != '.') { + only_dots = 0; + if (ch == '/' || ch == '\\') + has_slashes = 1; } } diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc index 0ab2290539..ebd559b66f 100644 --- a/winsup/cygwin/strfuncs.cc +++ b/winsup/cygwin/strfuncs.cc @@ -616,7 +616,11 @@ _sys_mbstowcs (mbtowc_p f_mbtowc, wchar_t *dst, size_t dlen, const char *src, to store them in a symmetric way. */ bytes = 1; if (dst) +#ifdef STRICTLY_7BIT_ASCII *ptr = L'\xf000' | *pmbs; +#else + *ptr = *pmbs; +#endif memset (&ps, 0, sizeof ps); }