|
1 | 1 | /* |
2 | | - * Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -222,54 +222,35 @@ char *setupMacOSXLocale(int cat) { |
222 | 222 | } |
223 | 223 | } |
224 | 224 |
|
225 | | -// 10.9 SDK does not include the NSOperatingSystemVersion struct. |
226 | | -// For now, create our own |
227 | | -typedef struct { |
228 | | - NSInteger majorVersion; |
229 | | - NSInteger minorVersion; |
230 | | - NSInteger patchVersion; |
231 | | -} OSVerStruct; |
232 | | - |
233 | 225 | void setOSNameAndVersion(java_props_t *sprops) { |
234 | 226 | // Hardcode os_name, and fill in os_version |
235 | 227 | sprops->os_name = strdup("Mac OS X"); |
236 | 228 |
|
237 | 229 | NSString *nsVerStr = NULL; |
238 | 230 | char* osVersionCStr = NULL; |
239 | | - // Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function, |
240 | | - // but it's not in the 10.9 SDK. So, call it via NSInvocation. |
241 | | - if ([[NSProcessInfo processInfo] respondsToSelector:@selector(operatingSystemVersion)]) { |
242 | | - OSVerStruct osVer; |
243 | | - NSMethodSignature *sig = [[NSProcessInfo processInfo] methodSignatureForSelector: |
244 | | - @selector(operatingSystemVersion)]; |
245 | | - NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:sig]; |
246 | | - invoke.selector = @selector(operatingSystemVersion); |
247 | | - [invoke invokeWithTarget:[NSProcessInfo processInfo]]; |
248 | | - [invoke getReturnValue:&osVer]; |
249 | | - |
250 | | - // Copy out the char* if running on version other than 10.16 Mac OS (10.16 == 11.x) |
251 | | - // or explicitly requesting version compatibility |
252 | | - if (!((long)osVer.majorVersion == 10 && (long)osVer.minorVersion >= 16) || |
253 | | - (getenv("SYSTEM_VERSION_COMPAT") != NULL)) { |
254 | | - if (osVer.patchVersion == 0) { // Omit trailing ".0" |
255 | | - nsVerStr = [NSString stringWithFormat:@"%ld.%ld", |
256 | | - (long)osVer.majorVersion, (long)osVer.minorVersion]; |
257 | | - } else { |
258 | | - nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld", |
259 | | - (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion]; |
260 | | - } |
| 231 | + NSOperatingSystemVersion osVer = [[NSProcessInfo processInfo] operatingSystemVersion]; |
| 232 | + // Copy out the char* if running on version other than 10.16 Mac OS (10.16 == 11.x) |
| 233 | + // or explicitly requesting version compatibility |
| 234 | + if (!((long)osVer.majorVersion == 10 && (long)osVer.minorVersion >= 16) || |
| 235 | + (getenv("SYSTEM_VERSION_COMPAT") != NULL)) { |
| 236 | + if (osVer.patchVersion == 0) { // Omit trailing ".0" |
| 237 | + nsVerStr = [NSString stringWithFormat:@"%ld.%ld", |
| 238 | + (long)osVer.majorVersion, (long)osVer.minorVersion]; |
261 | 239 | } else { |
262 | | - // Version 10.16, without explicit env setting of SYSTEM_VERSION_COMPAT |
263 | | - // AKA 11+ Read the *real* ProductVersion from the hidden link to avoid SYSTEM_VERSION_COMPAT |
264 | | - // If not found, fallback below to the SystemVersion.plist |
265 | | - NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : |
266 | | - @"/System/Library/CoreServices/.SystemVersionPlatform.plist"]; |
267 | | - if (version != NULL) { |
268 | | - nsVerStr = [version objectForKey : @"ProductVersion"]; |
269 | | - } |
| 240 | + nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld", |
| 241 | + (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion]; |
| 242 | + } |
| 243 | + } else { |
| 244 | + // Version 10.16, without explicit env setting of SYSTEM_VERSION_COMPAT |
| 245 | + // AKA 11+ Read the *real* ProductVersion from the hidden link to avoid SYSTEM_VERSION_COMPAT |
| 246 | + // If not found, fallback below to the SystemVersion.plist |
| 247 | + NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : |
| 248 | + @"/System/Library/CoreServices/.SystemVersionPlatform.plist"]; |
| 249 | + if (version != NULL) { |
| 250 | + nsVerStr = [version objectForKey : @"ProductVersion"]; |
270 | 251 | } |
271 | 252 | } |
272 | | - // Fallback if running on pre-10.9 Mac OS |
| 253 | + // Fallback to reading the SystemVersion.plist |
273 | 254 | if (nsVerStr == NULL) { |
274 | 255 | NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : |
275 | 256 | @"/System/Library/CoreServices/SystemVersion.plist"]; |
|
0 commit comments