Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/java/lang/java_props_md.c
32287 views
1
/*
2
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
27
#include <stdio.h>
28
#include <ctype.h>
29
#endif
30
#include <pwd.h>
31
#include <locale.h>
32
#ifndef ARCHPROPNAME
33
#error "The macro ARCHPROPNAME has not been defined"
34
#endif
35
#include <sys/utsname.h> /* For os_name and os_version */
36
#ifndef __ANDROID__
37
# include <langinfo.h> /* For nl_langinfo */
38
#else
39
# include "langinfo.h"
40
#endif
41
#include <stdlib.h>
42
#include <string.h>
43
#include <sys/types.h>
44
#include <unistd.h>
45
#include <sys/param.h>
46
#include <time.h>
47
#include <errno.h>
48
49
#ifdef MACOSX
50
#include "java_props_macosx.h"
51
#endif
52
53
#if defined(_ALLBSD_SOURCE)
54
#if !defined(P_tmpdir)
55
#include <paths.h>
56
#define P_tmpdir _PATH_VARTMP
57
#endif
58
#endif
59
60
#include "locale_str.h"
61
#include "java_props.h"
62
63
#if !defined(_ALLBSD_SOURCE)
64
#ifdef __linux__
65
#ifndef CODESET
66
#define CODESET _NL_CTYPE_CODESET_NAME
67
#endif
68
#else
69
#ifdef ALT_CODESET_KEY
70
#define CODESET ALT_CODESET_KEY
71
#endif
72
#endif
73
#endif /* !_ALLBSD_SOURCE */
74
75
#ifdef JAVASE_EMBEDDED
76
#include <dlfcn.h>
77
#include <sys/stat.h>
78
#endif
79
80
/* Take an array of string pairs (map of key->value) and a string (key).
81
* Examine each pair in the map to see if the first string (key) matches the
82
* string. If so, store the second string of the pair (value) in the value and
83
* return 1. Otherwise do nothing and return 0. The end of the map is
84
* indicated by an empty string at the start of a pair (key of "").
85
*/
86
static int
87
mapLookup(char* map[], const char* key, char** value) {
88
int i;
89
for (i = 0; strcmp(map[i], ""); i += 2){
90
if (!strcmp(key, map[i])){
91
*value = map[i + 1];
92
return 1;
93
}
94
}
95
return 0;
96
}
97
98
#ifndef P_tmpdir
99
#define P_tmpdir "/var/tmp"
100
#endif
101
102
static int ParseLocale(JNIEnv* env, int cat, char ** std_language, char ** std_script,
103
char ** std_country, char ** std_variant, char ** std_encoding) {
104
char *temp = NULL;
105
char *language = NULL, *country = NULL, *variant = NULL,
106
*encoding = NULL;
107
char *p, *encoding_variant, *old_temp, *old_ev;
108
char *lc;
109
110
/* Query the locale set for the category */
111
112
#ifdef MACOSX
113
lc = setupMacOSXLocale(cat); // malloc'd memory, need to free
114
#else
115
lc = setlocale(cat, NULL);
116
#endif
117
118
#ifndef __linux__
119
if (lc == NULL) {
120
return 0;
121
}
122
123
temp = malloc(strlen(lc) + 1);
124
if (temp == NULL) {
125
#ifdef MACOSX
126
free(lc); // malloced memory
127
#endif
128
JNU_ThrowOutOfMemoryError(env, NULL);
129
return 0;
130
}
131
132
if (cat == LC_CTYPE) {
133
/*
134
* Workaround for Solaris bug 4201684: Xlib doesn't like @euro
135
* locales. Since we don't depend on the libc @euro behavior,
136
* we just remove the qualifier.
137
* On Linux, the bug doesn't occur; on the other hand, @euro
138
* is needed there because it's a shortcut that also determines
139
* the encoding - without it, we wouldn't get ISO-8859-15.
140
* Therefore, this code section is Solaris-specific.
141
*/
142
strcpy(temp, lc);
143
p = strstr(temp, "@euro");
144
if (p != NULL) {
145
*p = '\0';
146
setlocale(LC_ALL, temp);
147
}
148
}
149
#else
150
if (lc == NULL || !strcmp(lc, "C") || !strcmp(lc, "POSIX")) {
151
lc = "en_US";
152
}
153
154
temp = malloc(strlen(lc) + 1);
155
if (temp == NULL) {
156
JNU_ThrowOutOfMemoryError(env, NULL);
157
return 0;
158
}
159
160
#endif
161
162
/*
163
* locale string format in Solaris is
164
* <language name>_<country name>.<encoding name>@<variant name>
165
* <country name>, <encoding name>, and <variant name> are optional.
166
*/
167
168
strcpy(temp, lc);
169
#ifdef MACOSX
170
free(lc); // malloced memory
171
#endif
172
/* Parse the language, country, encoding, and variant from the
173
* locale. Any of the elements may be missing, but they must occur
174
* in the order language_country.encoding@variant, and must be
175
* preceded by their delimiter (except for language).
176
*
177
* If the locale name (without .encoding@variant, if any) matches
178
* any of the names in the locale_aliases list, map it to the
179
* corresponding full locale name. Most of the entries in the
180
* locale_aliases list are locales that include a language name but
181
* no country name, and this facility is used to map each language
182
* to a default country if that's possible. It's also used to map
183
* the Solaris locale aliases to their proper Java locale IDs.
184
*/
185
186
encoding_variant = malloc(strlen(temp)+1);
187
if (encoding_variant == NULL) {
188
free(temp);
189
JNU_ThrowOutOfMemoryError(env, NULL);
190
return 0;
191
}
192
193
if ((p = strchr(temp, '.')) != NULL) {
194
strcpy(encoding_variant, p); /* Copy the leading '.' */
195
*p = '\0';
196
} else if ((p = strchr(temp, '@')) != NULL) {
197
strcpy(encoding_variant, p); /* Copy the leading '@' */
198
*p = '\0';
199
} else {
200
*encoding_variant = '\0';
201
}
202
203
if (mapLookup(locale_aliases, temp, &p)) {
204
old_temp = temp;
205
temp = realloc(temp, strlen(p)+1);
206
if (temp == NULL) {
207
free(old_temp);
208
free(encoding_variant);
209
JNU_ThrowOutOfMemoryError(env, NULL);
210
return 0;
211
}
212
strcpy(temp, p);
213
old_ev = encoding_variant;
214
encoding_variant = realloc(encoding_variant, strlen(temp)+1);
215
if (encoding_variant == NULL) {
216
free(old_ev);
217
free(temp);
218
JNU_ThrowOutOfMemoryError(env, NULL);
219
return 0;
220
}
221
// check the "encoding_variant" again, if any.
222
if ((p = strchr(temp, '.')) != NULL) {
223
strcpy(encoding_variant, p); /* Copy the leading '.' */
224
*p = '\0';
225
} else if ((p = strchr(temp, '@')) != NULL) {
226
strcpy(encoding_variant, p); /* Copy the leading '@' */
227
*p = '\0';
228
}
229
}
230
231
language = temp;
232
if ((country = strchr(temp, '_')) != NULL) {
233
*country++ = '\0';
234
}
235
236
p = encoding_variant;
237
if ((encoding = strchr(p, '.')) != NULL) {
238
p[encoding++ - p] = '\0';
239
p = encoding;
240
}
241
if ((variant = strchr(p, '@')) != NULL) {
242
p[variant++ - p] = '\0';
243
}
244
245
/* Normalize the language name */
246
if (std_language != NULL) {
247
*std_language = "en";
248
if (language != NULL && mapLookup(language_names, language, std_language) == 0) {
249
*std_language = malloc(strlen(language)+1);
250
strcpy(*std_language, language);
251
}
252
}
253
254
/* Normalize the country name */
255
if (std_country != NULL && country != NULL) {
256
if (mapLookup(country_names, country, std_country) == 0) {
257
*std_country = malloc(strlen(country)+1);
258
strcpy(*std_country, country);
259
}
260
}
261
262
/* Normalize the script and variant name. Note that we only use
263
* variants listed in the mapping array; others are ignored.
264
*/
265
if (variant != NULL) {
266
if (std_script != NULL) {
267
mapLookup(script_names, variant, std_script);
268
}
269
270
if (std_variant != NULL) {
271
mapLookup(variant_names, variant, std_variant);
272
}
273
}
274
275
/* Normalize the encoding name. Note that we IGNORE the string
276
* 'encoding' extracted from the locale name above. Instead, we use the
277
* more reliable method of calling nl_langinfo(CODESET). This function
278
* returns an empty string if no encoding is set for the given locale
279
* (e.g., the C or POSIX locales); we use the default ISO 8859-1
280
* converter for such locales.
281
*/
282
if (std_encoding != NULL) {
283
/* OK, not so reliable - nl_langinfo() gives wrong answers on
284
* Euro locales, in particular. */
285
if (strcmp(p, "ISO8859-15") == 0)
286
p = "ISO8859-15";
287
else
288
p = nl_langinfo(CODESET);
289
290
/* Convert the bare "646" used on Solaris to a proper IANA name */
291
if (strcmp(p, "646") == 0)
292
p = "ISO646-US";
293
294
/* return same result nl_langinfo would return for en_UK,
295
* in order to use optimizations. */
296
*std_encoding = (*p != '\0') ? p : "ISO8859-1";
297
298
#ifdef __linux__
299
/*
300
* Remap the encoding string to a different value for japanese
301
* locales on linux so that customized converters are used instead
302
* of the default converter for "EUC-JP". The customized converters
303
* omit support for the JIS0212 encoding which is not supported by
304
* the variant of "EUC-JP" encoding used on linux
305
*/
306
if (strcmp(p, "EUC-JP") == 0) {
307
*std_encoding = "EUC-JP-LINUX";
308
}
309
#else
310
if (strcmp(p,"eucJP") == 0) {
311
/* For Solaris use customized vendor defined character
312
* customized EUC-JP converter
313
*/
314
*std_encoding = "eucJP-open";
315
} else if (strcmp(p, "Big5") == 0 || strcmp(p, "BIG5") == 0) {
316
/*
317
* Remap the encoding string to Big5_Solaris which augments
318
* the default converter for Solaris Big5 locales to include
319
* seven additional ideographic characters beyond those included
320
* in the Java "Big5" converter.
321
*/
322
*std_encoding = "Big5_Solaris";
323
} else if (strcmp(p, "Big5-HKSCS") == 0) {
324
/*
325
* Solaris uses HKSCS2001
326
*/
327
*std_encoding = "Big5-HKSCS-2001";
328
}
329
#endif
330
#ifdef MACOSX
331
/*
332
* For the case on MacOS X where encoding is set to US-ASCII, but we
333
* don't have any encoding hints from LANG/LC_ALL/LC_CTYPE, use UTF-8
334
* instead.
335
*
336
* The contents of ASCII files will still be read and displayed
337
* correctly, but so will files containing UTF-8 characters beyond the
338
* standard ASCII range.
339
*
340
* Specifically, this allows apps launched by double-clicking a .jar
341
* file to correctly read UTF-8 files using the default encoding (see
342
* 8011194).
343
*/
344
if (strcmp(p,"US-ASCII") == 0 && getenv("LANG") == NULL &&
345
getenv("LC_ALL") == NULL && getenv("LC_CTYPE") == NULL) {
346
*std_encoding = "UTF-8";
347
}
348
#endif
349
}
350
351
free(temp);
352
free(encoding_variant);
353
354
return 1;
355
}
356
357
#ifdef JAVASE_EMBEDDED
358
/* Determine the default embedded toolkit based on whether libawt_xawt
359
* exists in the JRE. This can still be overridden by -Dawt.toolkit=XXX
360
*/
361
static char* getEmbeddedToolkit() {
362
Dl_info dlinfo;
363
char buf[MAXPATHLEN];
364
int32_t len;
365
char *p;
366
struct stat statbuf;
367
368
/* Get address of this library and the directory containing it. */
369
dladdr((void *)getEmbeddedToolkit, &dlinfo);
370
realpath((char *)dlinfo.dli_fname, buf);
371
len = strlen(buf);
372
p = strrchr(buf, '/');
373
/* Default AWT Toolkit on Linux and Solaris is XAWT (libawt_xawt.so). */
374
strncpy(p, "/libawt_xawt.so", MAXPATHLEN-len-1);
375
/* Check if it exists */
376
if (stat(buf, &statbuf) == -1 && errno == ENOENT) {
377
/* No - this is a reduced-headless-jre so use special HToolkit */
378
return "sun.awt.HToolkit";
379
}
380
else {
381
/* Yes - this is a headful JRE so fallback to SE defaults */
382
return NULL;
383
}
384
}
385
#endif
386
387
/* This function gets called very early, before VM_CALLS are setup.
388
* Do not use any of the VM_CALLS entries!!!
389
*/
390
java_props_t *
391
GetJavaProperties(JNIEnv *env)
392
{
393
static java_props_t sprops;
394
char *v; /* tmp var */
395
396
if (sprops.user_dir) {
397
return &sprops;
398
}
399
400
/* tmp dir */
401
sprops.tmp_dir = P_tmpdir;
402
#ifdef MACOSX
403
/* darwin has a per-user temp dir */
404
static char tmp_path[PATH_MAX];
405
int pathSize = confstr(_CS_DARWIN_USER_TEMP_DIR, tmp_path, PATH_MAX);
406
if (pathSize > 0 && pathSize <= PATH_MAX) {
407
sprops.tmp_dir = tmp_path;
408
}
409
#endif /* MACOSX */
410
411
/* Printing properties */
412
#ifdef MACOSX
413
sprops.printerJob = "sun.lwawt.macosx.CPrinterJob";
414
#else
415
sprops.printerJob = "sun.print.PSPrinterJob";
416
#endif
417
418
/* patches/service packs installed */
419
sprops.patch_level = "unknown";
420
421
/* Java 2D/AWT properties */
422
#ifdef MACOSX
423
// Always the same GraphicsEnvironment and Toolkit on Mac OS X
424
sprops.graphics_env = "sun.awt.CGraphicsEnvironment";
425
sprops.awt_toolkit = "sun.lwawt.macosx.LWCToolkit";
426
427
// check if we're in a GUI login session and set java.awt.headless=true if not
428
sprops.awt_headless = isInAquaSession() ? NULL : "true";
429
#else
430
sprops.graphics_env = "sun.awt.X11GraphicsEnvironment";
431
#ifdef JAVASE_EMBEDDED
432
sprops.awt_toolkit = getEmbeddedToolkit();
433
if (sprops.awt_toolkit == NULL) // default as below
434
#endif
435
sprops.awt_toolkit = "sun.awt.X11.XToolkit";
436
#endif
437
438
/* This is used only for debugging of font problems. */
439
v = getenv("JAVA2D_FONTPATH");
440
sprops.font_dir = v ? v : NULL;
441
442
#ifdef SI_ISALIST
443
/* supported instruction sets */
444
{
445
char list[258];
446
sysinfo(SI_ISALIST, list, sizeof(list));
447
sprops.cpu_isalist = strdup(list);
448
}
449
#else
450
sprops.cpu_isalist = NULL;
451
#endif
452
453
/* endianness of platform */
454
{
455
unsigned int endianTest = 0xff000000;
456
if (((char*)(&endianTest))[0] != 0)
457
sprops.cpu_endian = "big";
458
else
459
sprops.cpu_endian = "little";
460
}
461
462
/* os properties */
463
{
464
#ifdef MACOSX
465
setOSNameAndVersion(&sprops);
466
#else
467
struct utsname name;
468
uname(&name);
469
sprops.os_name = strdup(name.sysname);
470
#ifdef _AIX
471
{
472
char *os_version = malloc(strlen(name.version) +
473
strlen(name.release) + 2);
474
if (os_version != NULL) {
475
strcpy(os_version, name.version);
476
strcat(os_version, ".");
477
strcat(os_version, name.release);
478
}
479
sprops.os_version = os_version;
480
}
481
#else
482
sprops.os_version = strdup(name.release);
483
#endif /* _AIX */
484
#endif /* MACOSX */
485
486
sprops.os_arch = ARCHPROPNAME;
487
488
if (getenv("GNOME_DESKTOP_SESSION_ID") != NULL) {
489
sprops.desktop = "gnome";
490
}
491
else {
492
sprops.desktop = NULL;
493
}
494
}
495
496
/* ABI property (optional) */
497
#ifdef JDK_ARCH_ABI_PROP_NAME
498
sprops.sun_arch_abi = JDK_ARCH_ABI_PROP_NAME;
499
#endif
500
501
/* Determine the language, country, variant, and encoding from the host,
502
* and store these in the user.language, user.country, user.variant and
503
* file.encoding system properties. */
504
setlocale(LC_ALL, "");
505
if (ParseLocale(env, LC_CTYPE,
506
&(sprops.format_language),
507
&(sprops.format_script),
508
&(sprops.format_country),
509
&(sprops.format_variant),
510
&(sprops.encoding))) {
511
ParseLocale(env, LC_MESSAGES,
512
&(sprops.language),
513
&(sprops.script),
514
&(sprops.country),
515
&(sprops.variant),
516
NULL);
517
} else {
518
sprops.language = "en";
519
sprops.encoding = "ISO8859-1";
520
}
521
sprops.display_language = sprops.language;
522
sprops.display_script = sprops.script;
523
sprops.display_country = sprops.country;
524
sprops.display_variant = sprops.variant;
525
526
/* ParseLocale failed with OOME */
527
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
528
529
#ifdef MACOSX
530
sprops.sun_jnu_encoding = "UTF-8";
531
#else
532
sprops.sun_jnu_encoding = sprops.encoding;
533
#endif
534
535
#ifdef _ALLBSD_SOURCE
536
#if BYTE_ORDER == _LITTLE_ENDIAN
537
sprops.unicode_encoding = "UnicodeLittle";
538
#else
539
sprops.unicode_encoding = "UnicodeBig";
540
#endif
541
#else /* !_ALLBSD_SOURCE */
542
#ifdef __linux__
543
#if __BYTE_ORDER == __LITTLE_ENDIAN
544
sprops.unicode_encoding = "UnicodeLittle";
545
#else
546
sprops.unicode_encoding = "UnicodeBig";
547
#endif
548
#else
549
sprops.unicode_encoding = "UnicodeBig";
550
#endif
551
#endif /* _ALLBSD_SOURCE */
552
553
/* user properties */
554
{
555
struct passwd *pwent = getpwuid(getuid());
556
sprops.user_name = pwent ? strdup(pwent->pw_name) : "?";
557
#ifdef MACOSX
558
setUserHome(&sprops);
559
#else
560
sprops.user_home = pwent ? strdup(pwent->pw_dir) : NULL;
561
#endif
562
if (sprops.user_home == NULL) {
563
sprops.user_home = "?";
564
}
565
}
566
567
/* User TIMEZONE */
568
{
569
/*
570
* We defer setting up timezone until it's actually necessary.
571
* Refer to TimeZone.getDefault(). However, the system
572
* property is necessary to be able to be set by the command
573
* line interface -D. Here temporarily set a null string to
574
* timezone.
575
*/
576
tzset(); /* for compatibility */
577
sprops.timezone = "";
578
}
579
580
/* Current directory */
581
{
582
char buf[MAXPATHLEN];
583
errno = 0;
584
if (getcwd(buf, sizeof(buf)) == NULL)
585
JNU_ThrowByName(env, "java/lang/Error",
586
"Properties init: Could not determine current working directory.");
587
else
588
sprops.user_dir = strdup(buf);
589
}
590
591
sprops.file_separator = "/";
592
sprops.path_separator = ":";
593
sprops.line_separator = "\n";
594
595
#ifdef MACOSX
596
setProxyProperties(&sprops);
597
#endif
598
599
return &sprops;
600
}
601
602
jstring
603
GetStringPlatform(JNIEnv *env, nchar* cstr)
604
{
605
return JNU_NewStringPlatform(env, cstr);
606
}
607
608