Fossil SCM

Split WriteConsoleW call into multiple chunks, when necessary. See [https://connect.microsoft.com/VisualStudio/feedback/details/635230]

jan.nijtmans 2013-02-25 09:33 trunk
Commit 8031947e594396ad845a325bcc994078178ca39d
1 file changed +10 -7
+10 -7
--- src/utf8.c
+++ src/utf8.c
@@ -188,11 +188,11 @@
188188
** to a file, -1 is returned and nothing is written
189189
** to the console.
190190
*/
191191
int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
192192
#ifdef _WIN32
193
- int nChar;
193
+ int nChar, written = 0;
194194
wchar_t *zUnicode; /* Unicode version of zUtf8 */
195195
DWORD dummy;
196196
197197
static int istty[2] = { -1, -1 };
198198
if( istty[toStdErr] == -1 ){
@@ -207,17 +207,20 @@
207207
zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
208208
if( zUnicode==0 ){
209209
return 0;
210210
}
211211
nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
212
- if( nChar==0 ){
213
- free(zUnicode);
214
- return 0;
212
+ /* Split WriteConsoleW call into multiple chunks, if necessary. See:
213
+ * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
214
+ while( written < nChar ){
215
+ int size = nChar-written;
216
+ if (size > 26000) size = 26000;
217
+ WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode+written,
218
+ size, &dummy, 0);
219
+ written += size;
215220
}
216
- zUnicode[nChar] = '\0';
217
- WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar,
218
- &dummy, 0);
221
+ free(zUnicode);
219222
return nChar;
220223
#else
221224
return -1; /* No-op on unix */
222225
#endif
223226
}
224227
--- src/utf8.c
+++ src/utf8.c
@@ -188,11 +188,11 @@
188 ** to a file, -1 is returned and nothing is written
189 ** to the console.
190 */
191 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
192 #ifdef _WIN32
193 int nChar;
194 wchar_t *zUnicode; /* Unicode version of zUtf8 */
195 DWORD dummy;
196
197 static int istty[2] = { -1, -1 };
198 if( istty[toStdErr] == -1 ){
@@ -207,17 +207,20 @@
207 zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
208 if( zUnicode==0 ){
209 return 0;
210 }
211 nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
212 if( nChar==0 ){
213 free(zUnicode);
214 return 0;
 
 
 
 
 
215 }
216 zUnicode[nChar] = '\0';
217 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode, nChar,
218 &dummy, 0);
219 return nChar;
220 #else
221 return -1; /* No-op on unix */
222 #endif
223 }
224
--- src/utf8.c
+++ src/utf8.c
@@ -188,11 +188,11 @@
188 ** to a file, -1 is returned and nothing is written
189 ** to the console.
190 */
191 int fossil_utf8_to_console(const char *zUtf8, int nByte, int toStdErr){
192 #ifdef _WIN32
193 int nChar, written = 0;
194 wchar_t *zUnicode; /* Unicode version of zUtf8 */
195 DWORD dummy;
196
197 static int istty[2] = { -1, -1 };
198 if( istty[toStdErr] == -1 ){
@@ -207,17 +207,20 @@
207 zUnicode = malloc( (nChar + 1) *sizeof(zUnicode[0]) );
208 if( zUnicode==0 ){
209 return 0;
210 }
211 nChar = MultiByteToWideChar(CP_UTF8, 0, zUtf8, nByte, zUnicode, nChar);
212 /* Split WriteConsoleW call into multiple chunks, if necessary. See:
213 * <https://connect.microsoft.com/VisualStudio/feedback/details/635230> */
214 while( written < nChar ){
215 int size = nChar-written;
216 if (size > 26000) size = 26000;
217 WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE - toStdErr), zUnicode+written,
218 size, &dummy, 0);
219 written += size;
220 }
221 free(zUnicode);
 
 
222 return nChar;
223 #else
224 return -1; /* No-op on unix */
225 #endif
226 }
227

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button