1 /* |
1 /* |
2 * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
26 #include <sys/socket.h> |
26 #include <sys/socket.h> |
27 #include <netinet/in.h> |
27 #include <netinet/in.h> |
28 #include <arpa/inet.h> |
28 #include <arpa/inet.h> |
29 #include <objc/objc-runtime.h> |
29 #include <objc/objc-runtime.h> |
30 |
30 |
31 #include <Security/AuthSession.h> |
|
32 #include <CoreFoundation/CoreFoundation.h> |
31 #include <CoreFoundation/CoreFoundation.h> |
33 #include <SystemConfiguration/SystemConfiguration.h> |
32 #include <SystemConfiguration/SystemConfiguration.h> |
34 #include <Foundation/Foundation.h> |
33 #include <Foundation/Foundation.h> |
35 |
34 |
36 #include "java_props_macosx.h" |
35 #include "java_props_macosx.h" |
90 char *hyphenPos = strchr(languageString, '-'); |
89 char *hyphenPos = strchr(languageString, '-'); |
91 int langStrLen = strlen(languageString); |
90 int langStrLen = strlen(languageString); |
92 |
91 |
93 if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en" |
92 if (hyphenPos == NULL || // languageString contains ISO639 only, e.g., "en" |
94 languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn" |
93 languageString + langStrLen - hyphenPos == 5) { // ISO639-ScriptCode, e.g., "en-Latn" |
95 CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()), |
94 CFLocaleRef cflocale = CFLocaleCopyCurrent(); |
96 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding()); |
95 if (cflocale != NULL) { |
97 char *underscorePos = strrchr(localeString, '_'); |
96 CFStringGetCString(CFLocaleGetIdentifier(cflocale), |
98 char *region = NULL; |
97 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding()); |
99 |
98 char *underscorePos = strrchr(localeString, '_'); |
100 if (underscorePos != NULL) { |
99 char *region = NULL; |
101 region = underscorePos + 1; |
100 |
102 } |
101 if (underscorePos != NULL) { |
103 |
102 region = underscorePos + 1; |
104 if (region != NULL) { |
103 } |
105 strcat(languageString, "-"); |
104 |
106 strcat(languageString, region); |
105 if (region != NULL) { |
|
106 strcat(languageString, "-"); |
|
107 strcat(languageString, region); |
|
108 } |
|
109 CFRelease(cflocale); |
107 } |
110 } |
108 } |
111 } |
109 |
112 |
110 retVal = languageString; |
113 retVal = languageString; |
111 } |
114 } |
112 break; |
115 break; |
113 |
116 |
114 default: |
117 default: |
115 { |
118 { |
116 if (!CFStringGetCString(CFLocaleGetIdentifier(CFLocaleCopyCurrent()), |
119 CFLocaleRef cflocale = CFLocaleCopyCurrent(); |
117 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) { |
120 if (cflocale != NULL) { |
|
121 if (!CFStringGetCString(CFLocaleGetIdentifier(cflocale), |
|
122 localeString, LOCALEIDLENGTH, CFStringGetSystemEncoding())) { |
|
123 CFRelease(cflocale); |
|
124 return NULL; |
|
125 } |
|
126 |
|
127 retVal = localeString; |
|
128 CFRelease(cflocale); |
|
129 } else { |
118 return NULL; |
130 return NULL; |
119 } |
131 } |
120 |
|
121 retVal = localeString; |
|
122 } |
132 } |
123 break; |
133 break; |
124 } |
134 } |
125 |
135 |
126 if (retVal != NULL) { |
136 if (retVal != NULL) { |