File: testu16.c

package info (click to toggle)
dos2unix 7.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,972 kB
  • sloc: ansic: 4,109; makefile: 665; perl: 503; sh: 13
file content (31 lines) | stat: -rw-r--r-- 707 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <windows.h>
#include <fcntl.h>
#include <io.h>

/* This program demonstrates Unicode UTF-16 printed text redirected to a
   correct UTF-16 file.

   .\testu16.exe > out.txt

*/

int main () {

  int prevmode;


  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);


  return 0;
}