• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
re: How does one get the OS Product name programatically?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: How does one get the OS Product name programatically?


  • Subject: re: How does one get the OS Product name programatically?
  • From: Brendan Creane <email@hidden>
  • Date: Wed, 10 May 2006 22:30:40 -0700 (PDT)

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      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How does one get the OS Product name programatically?
      • From: "Finlay Dobbie" <email@hidden>
  • Prev by Date: Re: Shared mmap and data consistency upon a crash
  • Next by Date: Re: How does one get the OS Product name programatically?
  • Previous by thread: Re: How does one get the OS Product name programmatically?
  • Next by thread: Re: How does one get the OS Product name programatically?
  • Index(es):
    • Date
    • Thread