|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1998, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
45 | 45 | #endif
|
46 | 46 |
|
47 | 47 | typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
|
48 |
| -static boolean SetupI18nProps(LCID lcid, char** language, char** script, char** country, |
| 48 | +static BOOL SetupI18nProps(LCID lcid, char** language, char** script, char** country, |
49 | 49 | char** variant, char** encoding);
|
50 | 50 |
|
51 | 51 | #define PROPSIZE 9 // eight-letter + null terminator
|
@@ -128,21 +128,30 @@ getEncodingInternal(LCID lcid)
|
128 | 128 | return ret;
|
129 | 129 | }
|
130 | 130 |
|
131 |
| -static char* getConsoleEncoding() |
| 131 | +static char* getConsoleEncoding(BOOL output) |
132 | 132 | {
|
133 | 133 | size_t buflen = 16;
|
134 | 134 | char* buf = malloc(buflen);
|
135 | 135 | int cp;
|
136 | 136 | if (buf == NULL) {
|
137 | 137 | return NULL;
|
138 | 138 | }
|
139 |
| - cp = GetConsoleCP(); |
140 |
| - if (cp >= 874 && cp <= 950) |
| 139 | + if (output) { |
| 140 | + cp = GetConsoleOutputCP(); |
| 141 | + } else { |
| 142 | + cp = GetConsoleCP(); |
| 143 | + } |
| 144 | + if (cp >= 874 && cp <= 950) { |
141 | 145 | snprintf(buf, buflen, "ms%d", cp);
|
142 |
| - else if (cp == 65001) |
| 146 | + } else if (cp == 65001) { |
143 | 147 | snprintf(buf, buflen, "UTF-8");
|
144 |
| - else |
| 148 | + } else if (cp == 0) { |
| 149 | + // Failed to get the console code page |
| 150 | + free(buf); |
| 151 | + buf = NULL; |
| 152 | + } else { |
145 | 153 | snprintf(buf, buflen, "cp%d", cp);
|
| 154 | + } |
146 | 155 | return buf;
|
147 | 156 | }
|
148 | 157 |
|
@@ -221,7 +230,7 @@ getHomeFromShell32()
|
221 | 230 | return u_path;
|
222 | 231 | }
|
223 | 232 |
|
224 |
| -static boolean |
| 233 | +static BOOL |
225 | 234 | haveMMX(void)
|
226 | 235 | {
|
227 | 236 | return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
|
@@ -251,7 +260,7 @@ cpu_isalist(void)
|
251 | 260 | return NULL;
|
252 | 261 | }
|
253 | 262 |
|
254 |
| -static boolean |
| 263 | +static BOOL |
255 | 264 | SetupI18nProps(LCID lcid, char** language, char** script, char** country,
|
256 | 265 | char** variant, char** encoding) {
|
257 | 266 | /* script */
|
@@ -343,8 +352,8 @@ GetJavaProperties(JNIEnv* env)
|
343 | 352 | /* OS properties */
|
344 | 353 | {
|
345 | 354 | char buf[100];
|
346 |
| - boolean is_workstation; |
347 |
| - boolean is_64bit; |
| 355 | + BOOL is_workstation; |
| 356 | + BOOL is_64bit; |
348 | 357 | DWORD platformId;
|
349 | 358 | {
|
350 | 359 | OSVERSIONINFOEX ver;
|
@@ -677,15 +686,15 @@ GetJavaProperties(JNIEnv* env)
|
677 | 686 | hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
|
678 | 687 | if (hStdOutErr != INVALID_HANDLE_VALUE &&
|
679 | 688 | GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
|
680 |
| - sprops.stdout_encoding = getConsoleEncoding(); |
| 689 | + sprops.stdout_encoding = getConsoleEncoding(TRUE); |
681 | 690 | }
|
682 | 691 | hStdOutErr = GetStdHandle(STD_ERROR_HANDLE);
|
683 | 692 | if (hStdOutErr != INVALID_HANDLE_VALUE &&
|
684 | 693 | GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
|
685 | 694 | if (sprops.stdout_encoding != NULL)
|
686 | 695 | sprops.stderr_encoding = sprops.stdout_encoding;
|
687 | 696 | else
|
688 |
| - sprops.stderr_encoding = getConsoleEncoding(); |
| 697 | + sprops.stderr_encoding = getConsoleEncoding(TRUE); |
689 | 698 | }
|
690 | 699 | }
|
691 | 700 | }
|
|
0 commit comments