annotate src/solaris/native/java/lang/java_props_md.c @ 5852:95d1d08e82c1

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