this repo has no description
1/*
2 * Copyright (c) 2005 Finlay Dobbie
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Finlay Dobbie nor the names of his contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <CoreFoundation/CoreFoundation.h>
31#include <CoreFoundation/CFPriv.h>
32
33void usage(char *progname) {
34 fprintf(stderr, "Usage: %s [-productName|-productVersion|-buildVersion]\n", progname);
35 exit(1);
36}
37
38int main(int argc, char *argv[]) {
39 CFDictionaryRef dict= NULL;
40 CFStringRef str = NULL;
41 char cstr[256];
42
43 dict = _CFCopyServerVersionDictionary();
44 if (dict == NULL)
45 dict = _CFCopySystemVersionDictionary();
46 if (dict == NULL)
47 exit(1);
48
49 if (argc == 2) {
50 if (!strcmp(argv[1], "-productName"))
51 str = CFDictionaryGetValue(dict, _kCFSystemVersionProductNameKey);
52 else if (!strcmp(argv[1], "-productVersion")) {
53 /* On Darwin, we set MacOSXProductVersion to the corresponding OS X release.
54 This is for compatibility with scripts that set MACOSX_DEPLOYMENT_TARGET
55 based on sw_vers -productVersion */
56 str = CFDictionaryGetValue(dict, CFSTR("MacOSXProductVersion"));
57 if (str == NULL)
58 str = CFDictionaryGetValue(dict, _kCFSystemVersionProductVersionKey);
59 }
60 else if (!strcmp(argv[1], "-buildVersion"))
61 str = CFDictionaryGetValue(dict, _kCFSystemVersionBuildVersionKey);
62 else
63 usage(argv[0]);
64 CFRetain(str);
65 } else if (argc == 1) {
66 str = CFStringCreateWithFormat(NULL, NULL,
67 CFSTR("ProductName: %@\n"
68 "ProductVersion: %@\n"
69 "BuildVersion: %@"),
70 CFDictionaryGetValue(dict, _kCFSystemVersionProductNameKey),
71 CFDictionaryGetValue(dict, _kCFSystemVersionProductVersionKey),
72 CFDictionaryGetValue(dict, _kCFSystemVersionBuildVersionKey));
73 } else {
74 usage(argv[0]);
75 }
76
77 if (!CFStringGetCString(str, cstr, sizeof(cstr), CFStringGetSystemEncoding()))
78 exit(1);
79
80 printf("%s\n", cstr);
81
82 CFRelease(str);
83 CFRelease(dict);
84 return 0;
85}