Parcourir la source

Force UTF-16 output.

If we were compiled as a Unicode application, set stdout and stderr
output mode to UTF-16 text.  Doing so allows French and Italian accented
characters to show up correctly on the console.

We currently have no analogous method for fixing the output of NSSM when
compiled as an ANSI application.
Iain Patterson il y a 10 ans
Parent
commit
153133aeda
2 fichiers modifiés avec 11 ajouts et 0 suppressions
  1. 9 0
      nssm.cpp
  2. 2 0
      nssm.h

+ 9 - 0
nssm.cpp

@@ -85,6 +85,15 @@ int num_cpus() {
 int _tmain(int argc, TCHAR **argv) {
 int _tmain(int argc, TCHAR **argv) {
   check_console();
   check_console();
 
 
+#ifdef UNICODE
+  /*
+    Ensure we write in UTF-16 mode, so that non-ASCII characters don't get
+    mangled.  If we were compiled in ANSI mode it won't work.
+   */
+  _setmode(_fileno(stdout), _O_U16TEXT);
+  _setmode(_fileno(stderr), _O_U16TEXT);
+#endif
+
   /* Remember if we are admin */
   /* Remember if we are admin */
   check_admin();
   check_admin();
 
 

+ 2 - 0
nssm.h

@@ -2,6 +2,8 @@
 #define NSSM_H
 #define NSSM_H
 
 
 #define _WIN32_WINNT 0x0500
 #define _WIN32_WINNT 0x0500
+#include <fcntl.h>
+#include <io.h>
 #include <shlwapi.h>
 #include <shlwapi.h>
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>