@@ -222,23 +222,42 @@ 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
+
225
233
void setOSNameAndVersion (java_props_t * sprops ) {
226
234
// Hardcode os_name, and fill in os_version
227
235
sprops -> os_name = strdup ("Mac OS X" );
228
236
229
237
char * osVersionCStr = NULL ;
230
- // Mac OS 10.2 includes the [NSProcessInfo operatingSystemVersionString] function,
231
- // but it's not in the 10.2 SDK. So, call it via objc_msgSend_stret.
232
- if ([[NSProcessInfo processInfo ] respondsToSelector :@selector (operatingSystemVersionString )]) {
233
- NSString * (* procInfoFn )(id rec , SEL sel ) = (NSString * (* )(id , SEL ))objc_msgSend ;
234
- NSString * nsVerStr = procInfoFn ([NSProcessInfo processInfo ],
235
- @selector (operatingSystemVersionString ));
236
- if (nsVerStr != NULL ) {
237
- // Copy out the char*
238
- osVersionCStr = strdup ([nsVerStr UTF8String ]);
238
+ // Mac OS 10.9 includes the [NSProcessInfo operatingSystemVersion] function,
239
+ // but it's not in the 10.9 SDK. So, call it via NSInvocation.
240
+ if ([[NSProcessInfo processInfo ] respondsToSelector :@selector (operatingSystemVersion )]) {
241
+ OSVerStruct osVer ;
242
+ NSMethodSignature * sig = [[NSProcessInfo processInfo ] methodSignatureForSelector :
243
+ @selector (operatingSystemVersion )];
244
+ NSInvocation * invoke = [NSInvocation invocationWithMethodSignature :sig ];
245
+ invoke .selector = @selector (operatingSystemVersion );
246
+ [invoke invokeWithTarget :[NSProcessInfo processInfo ]];
247
+ [invoke getReturnValue :& osVer ];
248
+
249
+ NSString * nsVerStr ;
250
+ if (osVer .patchVersion == 0 ) { // Omit trailing ".0"
251
+ nsVerStr = [NSString stringWithFormat :@"%ld.%ld" ,
252
+ (long )osVer .majorVersion , (long )osVer .minorVersion ];
253
+ } else {
254
+ nsVerStr = [NSString stringWithFormat :@"%ld.%ld.%ld" ,
255
+ (long )osVer .majorVersion , (long )osVer .minorVersion , (long )osVer .patchVersion ];
239
256
}
257
+ // Copy out the char*
258
+ osVersionCStr = strdup ([nsVerStr UTF8String ]);
240
259
}
241
- // Fallback if running on pre-10.2 Mac OS
260
+ // Fallback if running on pre-10.9 Mac OS
242
261
if (osVersionCStr == NULL ) {
243
262
NSDictionary * version = [NSDictionary dictionaryWithContentsOfFile :
244
263
@"/System/Library/CoreServices/SystemVersion.plist" ];
0 commit comments