-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
java_props_md.c
749 lines (686 loc) · 25.5 KB
/
java_props_md.c
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
/*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include <windows.h>
#include <shlobj.h>
#include <objidl.h>
#include <locale.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <tchar.h>
#include <stdlib.h>
#include <Wincon.h>
#include "locale_str.h"
#include "java_props.h"
#ifndef VER_PLATFORM_WIN32_WINDOWS
#define VER_PLATFORM_WIN32_WINDOWS 1
#endif
#ifndef PROCESSOR_ARCHITECTURE_AMD64
#define PROCESSOR_ARCHITECTURE_AMD64 9
#endif
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
static boolean SetupI18nProps(LCID lcid, char** language, char** script, char** country,
char** variant, char** encoding);
#define PROPSIZE 9 // eight-letter + null terminator
#define SNAMESIZE 86 // max number of chars for LOCALE_SNAME is 85
static char *
getEncodingInternal(LCID lcid)
{
int codepage = 0;
char * ret = malloc(16);
if (ret == NULL) {
return NULL;
}
if (lcid == 0) { // for sun.jnu.encoding
codepage = GetACP();
_itoa_s(codepage, ret + 2, 14, 10);
} else if (GetLocaleInfo(lcid,
LOCALE_IDEFAULTANSICODEPAGE,
ret + 2, 14) != 0) {
codepage = atoi(ret + 2);
}
switch (codepage) {
case 0:
case 65001:
strcpy(ret, "UTF-8");
break;
case 874: /* 9:Thai */
case 932: /* 10:Japanese */
case 949: /* 12:Korean Extended Wansung */
case 950: /* 13:Chinese (Taiwan, Hongkong, Macau) */
case 1361: /* 15:Korean Johab */
ret[0] = 'M';
ret[1] = 'S';
break;
case 936:
strcpy(ret, "GBK");
break;
case 54936:
strcpy(ret, "GB18030");
break;
default:
ret[0] = 'C';
ret[1] = 'p';
break;
}
//Traditional Chinese Windows should use MS950_HKSCS_XP as the
//default encoding, if HKSCS patch has been installed.
// "old" MS950 0xfa41 -> u+e001
// "new" MS950 0xfa41 -> u+92db
if (strcmp(ret, "MS950") == 0) {
TCHAR mbChar[2] = {(char)0xfa, (char)0x41};
WCHAR unicodeChar;
MultiByteToWideChar(CP_ACP, 0, mbChar, 2, &unicodeChar, 1);
if (unicodeChar == 0x92db) {
strcpy(ret, "MS950_HKSCS_XP");
}
} else {
//SimpChinese Windows should use GB18030 as the default
//encoding, if gb18030 patch has been installed (on windows
//2000/XP, (1)Codepage 54936 will be available
//(2)simsun18030.ttc will exist under system fonts dir )
if (strcmp(ret, "GBK") == 0 && IsValidCodePage(54936)) {
char systemPath[MAX_PATH + 1];
char* gb18030Font = "\\FONTS\\SimSun18030.ttc";
FILE *f = NULL;
if (GetWindowsDirectory(systemPath, MAX_PATH + 1) != 0 &&
strlen(systemPath) + strlen(gb18030Font) < MAX_PATH + 1) {
strcat(systemPath, "\\FONTS\\SimSun18030.ttc");
if ((f = fopen(systemPath, "r")) != NULL) {
fclose(f);
strcpy(ret, "GB18030");
}
}
}
}
return ret;
}
static char* getConsoleEncoding()
{
size_t buflen = 16;
char* buf = malloc(buflen);
int cp;
if (buf == NULL) {
return NULL;
}
cp = GetConsoleCP();
if (cp >= 874 && cp <= 950)
snprintf(buf, buflen, "ms%d", cp);
else if (cp == 65001)
snprintf(buf, buflen, "UTF-8");
else
snprintf(buf, buflen, "cp%d", cp);
return buf;
}
// Exported entries for AWT
DllExport const char *
getEncodingFromLangID(LANGID langID)
{
return getEncodingInternal(MAKELCID(langID, SORT_DEFAULT));
}
// Returns BCP47 Language Tag
DllExport const char *
getJavaIDFromLangID(LANGID langID)
{
char * elems[5]; // lang, script, ctry, variant, encoding
char * ret;
int index;
ret = malloc(SNAMESIZE);
if (ret == NULL) {
return NULL;
}
for (index = 0; index < 5; index++) {
elems[index] = NULL;
}
if (SetupI18nProps(MAKELCID(langID, SORT_DEFAULT),
&(elems[0]), &(elems[1]), &(elems[2]), &(elems[3]), &(elems[4]))) {
// there always is the "language" tag
strcpy(ret, elems[0]);
// append other elements, if any
for (index = 1; index < 4; index++) {
if ((elems[index])[0] != '\0') {
strcat(ret, "-");
strcat(ret, elems[index]);
}
}
} else {
free(ret);
ret = NULL;
}
for (index = 0; index < 5; index++) {
if (elems[index] != NULL) {
free(elems[index]);
}
}
return ret;
}
/*
* Code to figure out the user's home directory using shell32.dll
*/
WCHAR*
getHomeFromShell32()
{
/*
* Note that we don't free the memory allocated
* by getHomeFromShell32.
*/
static WCHAR *u_path = NULL;
if (u_path == NULL) {
HRESULT hr;
/*
* SHELL32 DLL is delay load DLL and we can use the trick with
* __try/__except block.
*/
__try {
/*
* For Windows Vista and later (or patched MS OS) we need to use
* [SHGetKnownFolderPath] call to avoid MAX_PATH length limitation.
* Shell32.dll (version 6.0.6000 or later)
*/
hr = SHGetKnownFolderPath(&FOLDERID_Profile, KF_FLAG_DONT_VERIFY, NULL, &u_path);
} __except(EXCEPTION_EXECUTE_HANDLER) {
/* Exception: no [SHGetKnownFolderPath] entry */
hr = E_FAIL;
}
if (FAILED(hr)) {
WCHAR path[MAX_PATH+1];
/* fallback solution for WinXP and Windows 2000 */
hr = SHGetFolderPathW(NULL, CSIDL_FLAG_DONT_VERIFY | CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, path);
if (FAILED(hr)) {
/* we can't find the shell folder. */
u_path = NULL;
} else {
/* Just to be sure about the path length until Windows Vista approach.
* [S_FALSE] could not be returned due to [CSIDL_FLAG_DONT_VERIFY] flag and UNICODE version.
*/
path[MAX_PATH] = 0;
u_path = _wcsdup(path);
}
}
}
return u_path;
}
static boolean
haveMMX(void)
{
return IsProcessorFeaturePresent(PF_MMX_INSTRUCTIONS_AVAILABLE);
}
static const char *
cpu_isalist(void)
{
SYSTEM_INFO info;
GetSystemInfo(&info);
switch (info.wProcessorArchitecture) {
#ifdef PROCESSOR_ARCHITECTURE_IA64
case PROCESSOR_ARCHITECTURE_IA64: return "ia64";
#endif
#ifdef PROCESSOR_ARCHITECTURE_AMD64
case PROCESSOR_ARCHITECTURE_AMD64: return "amd64";
#endif
case PROCESSOR_ARCHITECTURE_INTEL:
switch (info.wProcessorLevel) {
case 6: return haveMMX()
? "pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86"
: "pentium_pro pentium i486 i386 i86";
case 5: return haveMMX()
? "pentium+mmx pentium i486 i386 i86"
: "pentium i486 i386 i86";
case 4: return "i486 i386 i86";
case 3: return "i386 i86";
}
}
return NULL;
}
static boolean
SetupI18nProps(LCID lcid, char** language, char** script, char** country,
char** variant, char** encoding) {
/* script */
char tmp[SNAMESIZE];
*script = malloc(PROPSIZE);
if (*script == NULL) {
return FALSE;
}
if (GetLocaleInfo(lcid,
LOCALE_SNAME, tmp, SNAMESIZE) == 0 ||
sscanf(tmp, "%*[a-z\\-]%1[A-Z]%[a-z]", *script, &((*script)[1])) == 0 ||
strlen(*script) != 4) {
(*script)[0] = '\0';
}
/* country */
*country = malloc(PROPSIZE);
if (*country == NULL) {
return FALSE;
}
if (GetLocaleInfo(lcid,
LOCALE_SISO3166CTRYNAME, *country, PROPSIZE) == 0 &&
GetLocaleInfo(lcid,
LOCALE_SISO3166CTRYNAME2, *country, PROPSIZE) == 0) {
(*country)[0] = '\0';
}
/* language */
*language = malloc(PROPSIZE);
if (*language == NULL) {
return FALSE;
}
if (GetLocaleInfo(lcid,
LOCALE_SISO639LANGNAME, *language, PROPSIZE) == 0 &&
GetLocaleInfo(lcid,
LOCALE_SISO639LANGNAME2, *language, PROPSIZE) == 0) {
/* defaults to en_US */
strcpy(*language, "en");
strcpy(*country, "US");
}
/* variant */
*variant = malloc(PROPSIZE);
if (*variant == NULL) {
return FALSE;
}
(*variant)[0] = '\0';
/* handling for Norwegian */
if (strcmp(*language, "nb") == 0) {
strcpy(*language, "no");
strcpy(*country , "NO");
} else if (strcmp(*language, "nn") == 0) {
strcpy(*language, "no");
strcpy(*country , "NO");
strcpy(*variant, "NY");
}
/* encoding */
*encoding = getEncodingInternal(lcid);
if (*encoding == NULL) {
return FALSE;
}
return TRUE;
}
// GetVersionEx is deprecated; disable the warning until a replacement is found
#pragma warning(disable : 4996)
java_props_t *
GetJavaProperties(JNIEnv* env)
{
static java_props_t sprops = {0};
int majorVersion;
int minorVersion;
int buildNumber = 0;
if (sprops.line_separator) {
return &sprops;
}
/* tmp dir */
{
WCHAR tmpdir[MAX_PATH + 1];
/* we might want to check that this succeed */
GetTempPathW(MAX_PATH + 1, tmpdir);
sprops.tmp_dir = _wcsdup(tmpdir);
}
/* OS properties */
{
char buf[100];
boolean is_workstation;
boolean is_64bit;
DWORD platformId;
{
OSVERSIONINFOEX ver;
ver.dwOSVersionInfoSize = sizeof(ver);
GetVersionEx((OSVERSIONINFO *) &ver);
majorVersion = ver.dwMajorVersion;
minorVersion = ver.dwMinorVersion;
/* distinguish Windows Server 2016+ by build number */
buildNumber = ver.dwBuildNumber;
is_workstation = (ver.wProductType == VER_NT_WORKSTATION);
platformId = ver.dwPlatformId;
sprops.patch_level = _strdup(ver.szCSDVersion);
}
{
SYSTEM_INFO si;
ZeroMemory(&si, sizeof(SYSTEM_INFO));
GetNativeSystemInfo(&si);
is_64bit = (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64);
}
do {
// Read the major and minor version number from kernel32.dll
VS_FIXEDFILEINFO *file_info;
WCHAR kernel32_path[MAX_PATH];
DWORD version_size;
LPTSTR version_info;
UINT len, ret;
// Get the full path to \Windows\System32\kernel32.dll and use that for
// determining what version of Windows we're running on.
len = MAX_PATH - (UINT)strlen("\\kernel32.dll") - 1;
ret = GetSystemDirectoryW(kernel32_path, len);
if (ret == 0 || ret > len) {
break;
}
wcsncat(kernel32_path, L"\\kernel32.dll", MAX_PATH - ret);
version_size = GetFileVersionInfoSizeW(kernel32_path, NULL);
if (version_size == 0) {
break;
}
version_info = (LPTSTR)malloc(version_size);
if (version_info == NULL) {
break;
}
if (!GetFileVersionInfoW(kernel32_path, 0, version_size, version_info)) {
free(version_info);
break;
}
if (!VerQueryValueW(version_info, L"\\", (LPVOID*)&file_info, &len)) {
free(version_info);
break;
}
majorVersion = HIWORD(file_info->dwProductVersionMS);
minorVersion = LOWORD(file_info->dwProductVersionMS);
buildNumber = HIWORD(file_info->dwProductVersionLS);
free(version_info);
} while (0);
/*
* From msdn page on OSVERSIONINFOEX, current as of this
* writing, decoding of dwMajorVersion and dwMinorVersion.
*
* Operating system dwMajorVersion dwMinorVersion
* ================== ============== ==============
*
* Windows 95 4 0
* Windows 98 4 10
* Windows ME 4 90
* Windows 3.51 3 51
* Windows NT 4.0 4 0
* Windows 2000 5 0
* Windows XP 32 bit 5 1
* Windows Server 2003 family 5 2
* Windows XP 64 bit 5 2
* where ((&ver.wServicePackMinor) + 2) = 1
* and si.wProcessorArchitecture = 9
* Windows Vista family 6 0 (VER_NT_WORKSTATION)
* Windows Server 2008 6 0 (!VER_NT_WORKSTATION)
* Windows 7 6 1 (VER_NT_WORKSTATION)
* Windows Server 2008 R2 6 1 (!VER_NT_WORKSTATION)
* Windows 8 6 2 (VER_NT_WORKSTATION)
* Windows Server 2012 6 2 (!VER_NT_WORKSTATION)
* Windows Server 2012 R2 6 3 (!VER_NT_WORKSTATION)
* Windows 10 10 0 (VER_NT_WORKSTATION)
* Windows 11 10 0 (VER_NT_WORKSTATION)
* where (buildNumber >= 22000)
* Windows Server 2016 10 0 (!VER_NT_WORKSTATION)
* Windows Server 2019 10 0 (!VER_NT_WORKSTATION)
* where (buildNumber > 17762)
* Windows Server 2022 10 0 (!VER_NT_WORKSTATION)
* where (buildNumber > 20347)
*
* This mapping will presumably be augmented as new Windows
* versions are released.
*/
switch (platformId) {
case VER_PLATFORM_WIN32_WINDOWS:
if (majorVersion == 4) {
switch (minorVersion) {
case 0: sprops.os_name = "Windows 95"; break;
case 10: sprops.os_name = "Windows 98"; break;
case 90: sprops.os_name = "Windows Me"; break;
default: sprops.os_name = "Windows 9X (unknown)"; break;
}
} else {
sprops.os_name = "Windows 9X (unknown)";
}
break;
case VER_PLATFORM_WIN32_NT:
if (majorVersion <= 4) {
sprops.os_name = "Windows NT";
} else if (majorVersion == 5) {
switch (minorVersion) {
case 0: sprops.os_name = "Windows 2000"; break;
case 1: sprops.os_name = "Windows XP"; break;
case 2:
/*
* From MSDN OSVERSIONINFOEX and SYSTEM_INFO documentation:
*
* "Because the version numbers for Windows Server 2003
* and Windows XP 6u4 bit are identical, you must also test
* whether the wProductType member is VER_NT_WORKSTATION.
* and si.wProcessorArchitecture is
* PROCESSOR_ARCHITECTURE_AMD64 (which is 9)
* If it is, the operating system is Windows XP 64 bit;
* otherwise, it is Windows Server 2003."
*/
if (is_workstation && is_64bit) {
sprops.os_name = "Windows XP"; /* 64 bit */
} else {
sprops.os_name = "Windows 2003";
}
break;
default: sprops.os_name = "Windows NT (unknown)"; break;
}
} else if (majorVersion == 6) {
/*
* See table in MSDN OSVERSIONINFOEX documentation.
*/
if (is_workstation) {
switch (minorVersion) {
case 0: sprops.os_name = "Windows Vista"; break;
case 1: sprops.os_name = "Windows 7"; break;
case 2: sprops.os_name = "Windows 8"; break;
case 3: sprops.os_name = "Windows 8.1"; break;
default: sprops.os_name = "Windows NT (unknown)";
}
} else {
switch (minorVersion) {
case 0: sprops.os_name = "Windows Server 2008"; break;
case 1: sprops.os_name = "Windows Server 2008 R2"; break;
case 2: sprops.os_name = "Windows Server 2012"; break;
case 3: sprops.os_name = "Windows Server 2012 R2"; break;
default: sprops.os_name = "Windows NT (unknown)";
}
}
} else if (majorVersion == 10) {
if (is_workstation) {
switch (minorVersion) {
case 0:
/* Windows 11 21H2 (original release) build number is 22000 */
if (buildNumber >= 22000) {
sprops.os_name = "Windows 11";
} else {
sprops.os_name = "Windows 10";
}
break;
default: sprops.os_name = "Windows NT (unknown)";
}
} else {
switch (minorVersion) {
case 0:
/* Windows server 2019 GA 10/2018 build number is 17763 */
/* Windows server 2022 build number is 20348 */
if (buildNumber > 20347) {
sprops.os_name = "Windows Server 2022";
} else if (buildNumber > 17762) {
sprops.os_name = "Windows Server 2019";
} else {
sprops.os_name = "Windows Server 2016";
}
break;
default: sprops.os_name = "Windows NT (unknown)";
}
}
} else {
sprops.os_name = "Windows NT (unknown)";
}
break;
default:
sprops.os_name = "Windows (unknown)";
break;
}
snprintf(buf, sizeof(buf), "%d.%d", majorVersion, minorVersion);
sprops.os_version = _strdup(buf);
#if defined(_M_AMD64)
sprops.os_arch = "amd64";
#elif defined(_X86_)
sprops.os_arch = "x86";
#elif defined(_M_ARM64)
sprops.os_arch = "aarch64";
#else
sprops.os_arch = "unknown";
#endif
}
/* Endianness of platform */
{
unsigned int endianTest = 0xff000000;
if (((char*)(&endianTest))[0] != 0) {
sprops.cpu_endian = "big";
} else {
sprops.cpu_endian = "little";
}
}
/* CPU ISA list */
sprops.cpu_isalist = cpu_isalist();
/*
* User name
* We try to avoid calling GetUserName as it turns out to
* be surprisingly expensive on NT. It pulls in an extra
* 100 K of footprint.
*/
{
WCHAR *uname = _wgetenv(L"USERNAME");
if (uname != NULL && wcslen(uname) > 0) {
sprops.user_name = _wcsdup(uname);
} else {
DWORD buflen = 0;
if (GetUserNameW(NULL, &buflen) == 0 &&
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
uname = (WCHAR*)malloc(buflen * sizeof(WCHAR));
if (uname != NULL && GetUserNameW(uname, &buflen) == 0) {
free(uname);
uname = NULL;
}
} else {
uname = NULL;
}
sprops.user_name = (uname != NULL) ? uname : L"unknown";
}
}
/*
* Home directory
*
* The normal result is that for a given user name XXX:
* On multi-user NT, user.home gets set to c:\winnt\profiles\XXX.
* On multi-user Win95, user.home gets set to c:\windows\profiles\XXX.
* On single-user Win95, user.home gets set to c:\windows.
*/
{
WCHAR *homep = getHomeFromShell32();
if (homep == NULL) {
homep = L"C:\\";
}
sprops.user_home = homep;
}
/*
* user.language
* user.script, user.country, user.variant (if user's environment specifies them)
* file.encoding
*/
{
/*
* query the system for the current system default locale
* (which is a Windows LCID value),
*/
LCID userDefaultLCID = GetUserDefaultLCID();
LANGID userDefaultUILang = GetUserDefaultUILanguage();
LCID userDefaultUILCID = MAKELCID(userDefaultUILang, SORTIDFROMLCID(userDefaultLCID));
{
char * display_encoding;
HANDLE hStdOutErr;
// Windows UI Language selection list only cares "language"
// information of the UI Language. For example, the list
// just lists "English" but it actually means "en_US", and
// the user cannot select "en_GB" (if exists) in the list.
// So, this hack is to use the user LCID region information
// for the UI Language, if the "language" portion of those
// two locales are the same.
if (PRIMARYLANGID(LANGIDFROMLCID(userDefaultLCID)) ==
PRIMARYLANGID(userDefaultUILang)) {
userDefaultUILCID = userDefaultLCID;
}
SetupI18nProps(userDefaultLCID,
&sprops.format_language,
&sprops.format_script,
&sprops.format_country,
&sprops.format_variant,
&sprops.encoding);
SetupI18nProps(userDefaultUILCID,
&sprops.display_language,
&sprops.display_script,
&sprops.display_country,
&sprops.display_variant,
&display_encoding);
sprops.sun_jnu_encoding = getEncodingInternal(0);
if (sprops.sun_jnu_encoding == NULL) {
sprops.sun_jnu_encoding = "UTF-8";
}
if (LANGIDFROMLCID(userDefaultLCID) == 0x0c04 && majorVersion == 6) {
// MS claims "Vista has built-in support for HKSCS-2004.
// All of the HKSCS-2004 characters have Unicode 4.1.
// PUA code point assignments". But what it really means
// is that the HKSCS-2004 is ONLY supported in Unicode.
// Test indicates the MS950 in its zh_HK locale is a
// "regular" MS950 which does not handle HKSCS-2004 at
// all. Set encoding to MS950_HKSCS.
sprops.encoding = "MS950_HKSCS";
sprops.sun_jnu_encoding = "MS950_HKSCS";
}
hStdOutErr = GetStdHandle(STD_OUTPUT_HANDLE);
if (hStdOutErr != INVALID_HANDLE_VALUE &&
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
sprops.stdout_encoding = getConsoleEncoding();
}
hStdOutErr = GetStdHandle(STD_ERROR_HANDLE);
if (hStdOutErr != INVALID_HANDLE_VALUE &&
GetFileType(hStdOutErr) == FILE_TYPE_CHAR) {
if (sprops.stdout_encoding != NULL)
sprops.stderr_encoding = sprops.stdout_encoding;
else
sprops.stderr_encoding = getConsoleEncoding();
}
}
}
sprops.unicode_encoding = "UnicodeLittle";
/* User TIMEZONE
* We defer setting up timezone until it's actually necessary.
* Refer to TimeZone.getDefault(). The system property
* is able to be set by the command line interface -Duser.timezone.
*/
/* Current directory */
{
WCHAR buf[MAX_PATH];
if (GetCurrentDirectoryW(sizeof(buf)/sizeof(WCHAR), buf) != 0)
sprops.user_dir = _wcsdup(buf);
}
sprops.file_separator = "\\";
sprops.path_separator = ";";
sprops.line_separator = "\r\n";
return &sprops;
}
jstring
GetStringPlatform(JNIEnv *env, nchar* wcstr)
{
return (*env)->NewString(env, wcstr, (jsize)wcslen(wcstr));
}