From 6ab2da6525debb34ba20ecf85fc431e44c52ff09 Mon Sep 17 00:00:00 2001
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Fri, 20 Feb 2015 13:56:22 +0000
Subject: [PATCH 48/N] Handle 8-bit characters under LOCALE=C

When the character set is specified as ASCII (by setting the locale to
`C`), we should handle data outside the 7-bit range gracefully by simply
copying it, even if it is technically no longer ASCII.

Cygwin, however, wants to be a lot stricter than that.

Let's be more lenient in MSYS2 by making the strict 7-bit only handling
contingent on the `STRICTLY_7BIT_ASCII` macro (which we never set
because we don't want it).

This addresses the expectations of two of Git's test cases:
t7400.108(submodule with UTF-8 name) and t9300.193(X: handling
encoding).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 newlib/libc/stdlib/mbtowc_r.c | 2 +-
 newlib/libc/stdlib/wctomb_r.c | 2 +-
 winsup/cygwin/strfuncs.cc     | 4 ++++
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/stdlib/mbtowc_r.c b/newlib/libc/stdlib/mbtowc_r.c
index ca876f9..ee43736 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 a7f87cd..2c536ce 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/strfuncs.cc b/winsup/cygwin/strfuncs.cc
index 0ab2290..ebd559b 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);
 	}
 
