diff options
Diffstat (limited to 'test/testu16.c')
-rw-r--r--[-rwxr-xr-x] | test/testu16.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/test/testu16.c b/test/testu16.c index 8ed706a..d0a8f9e 100755..100644 --- a/test/testu16.c +++ b/test/testu16.c @@ -3,44 +3,27 @@ #include <fcntl.h>
#include <io.h>
-/* This program demonstrates that when Unicode printed text is redirected to
- a file, the file is not in correct UTF-16.
+/* This program demonstrates Unicode UTF-16 printed text redirected to a
+ correct UTF-16 file.
+
+ .\testu16.exe > out.txt
+
*/
int main () {
int prevmode;
-/*
- When the output of this program is redirected to a file in Windows Command
- Prompt you get for line breaks 0d0a 00, while it should be 0d00 0a00.
-
-c:\test>.\testu16.exe > o.txt
-
-c:\test>xxd o.txt
-0000000: 6f00 6e00 6500 0d0a 0074 0077 006f 000d o.n.e....t.w.o..
-0000010: 0a00 7400 6800 7200 6500 6500 0d0a 00 ..t.h.r.e.e....
-
-
-
- When the output is redirected to a file in PowerShell, null characters
- 0000 are inserted. It looks like UTF-32 with an UTF-16 BOM and UTF-16 line
- breaks.
-
-PS C:\test> .\testu16.exe > p.txt
-PS C:\test> xxd p.txt
-0000000: fffe 6f00 0000 6e00 0000 6500 0000 0d00 ..o...n...e.....
-0000010: 0a00 0000 7400 0000 7700 0000 6f00 0000 ....t...w...o...
-0000020: 0d00 0a00 0000 7400 0000 6800 0000 7200 ......t...h...r.
-0000030: 0000 6500 0000 6500 0000 0d00 0a00 0000 ..e...e.........
-0000040: 0d00 0a00 ....
-
-*/
prevmode = _setmode(_fileno(stdout), _O_U16TEXT);
+ /* We need to print an UTF-16 BOM for correct redirection in PowerShell. */
+ fwprintf(stdout, L"\xfeff");
fwprintf(stdout,L"one\n");
fwprintf(stdout,L"two\n");
fwprintf(stdout,L"three\n");
+ /* Flushing stdout is required to get correct UTF-16.
+ This is required for both CMD.exe and PowerShell. */
+ fflush(stdout);
_setmode(_fileno(stdout), prevmode);
|