re: How does one get the OS Product name programatically?
site_archiver@lists.apple.com Delivered-To: Darwin-dev@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding; b=qk4XMNWBNYE7K6+ieYytr+Pus7mOJUuUSa0Njtq6pUb/H7WZaPU63ztGRCXrXxAK8J/fajQDHmJYpSnBNQNhRf7h1KBF458zyrddrbpGf4+gWcvWE5uwl+no4kXatSHXVv1yD55Mwm1qGgOdxGVpzqhywRE74rMhwpsROaxsV0k= ; Here's a (reconstructed) copy of sw_vers.c (source from cached copy of http://gobsd.com/code/darwin/build/sw_vers.c). CFDictionaryGetValue() is the method for retrieving the contents of the plists that you discovered. cheers, bcreane #include <CoreFoundation/CoreFoundation.h> CF_EXPORT const CFStringRef _kCFSystemVersionProductNameKey; CF_EXPORT const CFStringRef _kCFSystemVersionProductCopyrightKey; CF_EXPORT const CFStringRef _kCFSystemVersionProductVersionKey; CF_EXPORT const CFStringRef _kCFSystemVersionProductVersionExtraKey; CF_EXPORT const CFStringRef _kCFSystemVersionProductUserVisibleVersionKey; // For loginwindow; see 2987512 CF_EXPORT const CFStringRef _kCFSystemVersionBuildVersionKey; CF_EXPORT const CFStringRef _kCFSystemVersionProductVersionStringKey; // Localized string for the string "Version" CF_EXPORT const CFStringRef _kCFSystemVersionBuildStringKey; void usage(char *progname) { fprintf(stderr, "Usage: %s [-productName|-productVersion|-buildVersion]\n", progname); exit(1); } int main(int argc, char *argv[]) { CFDictionaryRef dict= NULL; CFStringRef str = NULL; char cstr[256]; dict = _CFCopyServerVersionDictionary(); if (dict == NULL) dict = _CFCopySystemVersionDictionary(); if (dict == NULL) exit(1); if (argc == 2) { if (!strcmp(argv[1], "-productName")) str = CFDictionaryGetValue(dict, _kCFSystemVersionProductNameKey); else if (!strcmp(argv[1], "-productVersion")) { /* On Darwin, we set MacOSXProductVersion to the corresponding OS X release. This is for compatibility with scripts that set MACOSX_DEPLOYMENT_TARGET based on sw_vers -productVersion */ str = CFDictionaryGetValue(dict, CFSTR("MacOSXProductVersion")); if (str == NULL) str = CFDictionaryGetValue(dict, _kCFSystemVersionProductVersionKey); } else if (!strcmp(argv[1], "-buildVersion")) str = CFDictionaryGetValue(dict, _kCFSystemVersionBuildVersionKey); else usage(argv[0]); CFRetain(str); } else if (argc == 1) { str = CFStringCreateWithFormat(NULL, NULL, CFSTR("ProductName: %@\n" "ProductVersion: %@\n" "BuildVersion: %@"), CFDictionaryGetValue(dict, _kCFSystemVersionProductNameKey), CFDictionaryGetValue(dict, _kCFSystemVersionProductVersionKey), CFDictionaryGetValue(dict, _kCFSystemVersionBuildVersionKey)); } else { usage(argv[0]); } if (!CFStringGetCString(str, cstr, sizeof(cstr), CFStringGetSystemEncoding())) exit(1); printf("%s\n", cstr); CFRelease(str); CFRelease(dict); return 0; } _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com
participants (1)
-
Brendan Creane