< prev index next >
src/java.base/macosx/native/libjava/java_props_macosx.c
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1998, 2015, 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
--- 1,7 ----
/*
! * Copyright (c) 1998, 2016, 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
*** 21,54 ****
* 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 <dlfcn.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <Security/AuthSession.h>
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <Foundation/Foundation.h>
#include "java_props_macosx.h"
- // need dlopen/dlsym trick to avoid pulling in JavaRuntimeSupport before libjava.dylib is loaded
- static void *getJRSFramework() {
- static void *jrsFwk = NULL;
- #ifndef STATIC_BUILD
- // JavaRuntimeSupport doesn't support static Java runtimes
- if (jrsFwk == NULL) {
- jrsFwk = dlopen("/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaRuntimeSupport.framework/JavaRuntimeSupport", RTLD_LAZY | RTLD_LOCAL);
- }
- #endif
- return jrsFwk;
- }
-
char *getPosixLocale(int cat) {
char *lc = setlocale(cat, NULL);
if ((lc == NULL) || (strcmp(lc, "C") == 0)) {
lc = getenv("LANG");
}
--- 21,42 ----
* 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 <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+ #include <objc/objc-runtime.h>
#include <Security/AuthSession.h>
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SystemConfiguration.h>
#include <Foundation/Foundation.h>
#include "java_props_macosx.h"
char *getPosixLocale(int cat) {
char *lc = setlocale(cat, NULL);
if ((lc == NULL) || (strcmp(lc, "C") == 0)) {
lc = getenv("LANG");
}
*** 59,80 ****
#define LOCALEIDLENGTH 128
char *getMacOSXLocale(int cat) {
switch (cat) {
case LC_MESSAGES:
{
! void *jrsFwk = getJRSFramework();
! if (jrsFwk == NULL) return NULL;
!
! char *(*JRSCopyPrimaryLanguage)() = dlsym(jrsFwk, "JRSCopyPrimaryLanguage");
! char *primaryLanguage = JRSCopyPrimaryLanguage ? JRSCopyPrimaryLanguage() : NULL;
! if (primaryLanguage == NULL) return NULL;
!
! char *(*JRSCopyCanonicalLanguageForPrimaryLanguage)(char *) = dlsym(jrsFwk, "JRSCopyCanonicalLanguageForPrimaryLanguage");
! char *canonicalLanguage = JRSCopyCanonicalLanguageForPrimaryLanguage ? JRSCopyCanonicalLanguageForPrimaryLanguage(primaryLanguage) : NULL;
! free (primaryLanguage);
!
! return canonicalLanguage;
}
break;
default:
{
char localeString[LOCALEIDLENGTH];
--- 47,82 ----
#define LOCALEIDLENGTH 128
char *getMacOSXLocale(int cat) {
switch (cat) {
case LC_MESSAGES:
{
! // get preferred language code
! CFArrayRef languages = CFLocaleCopyPreferredLanguages();
! if (languages == NULL) {
! return NULL;
! }
! if (CFArrayGetCount(languages) <= 0) {
! CFRelease(languages);
! return NULL;
! }
! CFStringRef primaryLanguage = (CFStringRef)CFArrayGetValueAtIndex(languages, 0);
! if (primaryLanguage == NULL) {
! CFRelease(languages); // was missing from original patch
! return NULL;
! }
! char languageString[LOCALEIDLENGTH];
! if (CFStringGetCString(primaryLanguage, languageString,
! LOCALEIDLENGTH, CFStringGetSystemEncoding()) == false) {
! CFRelease(languages);
! return NULL;
! }
! CFRelease(languages);
! if (languageString[2] == '-') {
! // aa-AA into aa_AA
! languageString[2] = '_'; // BCP 47 lang-region --> ISO_639-1
! }
! return strdup(languageString);
}
break;
default:
{
char localeString[LOCALEIDLENGTH];
*** 90,107 ****
}
char *setupMacOSXLocale(int cat) {
char * ret = getMacOSXLocale(cat);
- if (cat == LC_MESSAGES && ret != NULL) {
- void *jrsFwk = getJRSFramework();
- if (jrsFwk != NULL) {
- void (*JRSSetDefaultLocalization)(char *) = dlsym(jrsFwk, "JRSSetDefaultLocalization");
- if (JRSSetDefaultLocalization) JRSSetDefaultLocalization(ret);
- }
- }
-
if (ret == NULL) {
return getPosixLocale(cat);
} else {
return ret;
}
--- 92,101 ----
*** 124,149 ****
}
}
return 0;
}
void setOSNameAndVersion(java_props_t *sprops) {
/* Don't rely on JRSCopyOSName because there's no guarantee the value will
* remain the same, or even if the JRS functions will continue to be part of
* Mac OS X. So hardcode os_name, and fill in os_version if we can.
*/
sprops->os_name = strdup("Mac OS X");
! void *jrsFwk = getJRSFramework();
! if (jrsFwk != NULL) {
! char *(*copyOSVersion)() = dlsym(jrsFwk, "JRSCopyOSVersion");
! if (copyOSVersion != NULL) {
! sprops->os_version = copyOSVersion();
! return;
}
}
! sprops->os_version = strdup("Unknown");
}
static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, CFStringRef inHostKey, CFStringRef inPortKey, CFStringRef *outProxyHost, int *ioProxyPort) {
/* See if the proxy is enabled. */
--- 118,159 ----
}
}
return 0;
}
+ // 10.9 SDK does not include the NSOperatingSystemVersion struct.
+ // For now, create our own
+ typedef struct {
+ NSInteger majorVersion;
+ NSInteger minorVersion;
+ NSInteger patchVersion;
+ } OSVerStruct;
+
void setOSNameAndVersion(java_props_t *sprops) {
/* Don't rely on JRSCopyOSName because there's no guarantee the value will
* remain the same, or even if the JRS functions will continue to be part of
* Mac OS X. So hardcode os_name, and fill in os_version if we can.
*/
sprops->os_name = strdup("Mac OS X");
! char *osVersionCStr = NULL;
! // Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function,
! // but it's not in the 10.9 SDK. So, call it via objc_msgSend_stret.
! if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) {
! OSVerStruct (*procInfoFn)(id rec, SEL sel) = (OSVerStruct(*)(id, SEL))objc_msgSend_stret;
! OSVerStruct osVer = procInfoFn([NSProcessInfo processInfo],
! @selector(operatingSystemVersion));
! NSString *nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
! (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion];
! // Copy out the char*
! osVersionCStr = strdup([nsVerStr UTF8String]);
}
+
+ if (osVersionCStr == NULL) {
+ osVersionCStr = strdup("Unknown");
}
! sprops->os_version = osVersionCStr;
}
static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, CFStringRef inHostKey, CFStringRef inPortKey, CFStringRef *outProxyHost, int *ioProxyPort) {
/* See if the proxy is enabled. */
< prev index next >