]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/safe_vproc.c
mDNSResponder-320.5.1.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / safe_vproc.c
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2009 Apple Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #include <stdlib.h>
19 #include <assert.h>
20 #include <vproc.h>
21 #include "safe_vproc.h"
22 #include "mDNSDebug.h"
23 #include <TargetConditionals.h>
24
25 #if defined(VPROC_HAS_TRANSACTIONS) && !TARGET_OS_EMBEDDED
26
27 static vproc_transaction_t transaction = NULL;
28
29 void safe_vproc_transaction_begin(void)
30 {
31 if (vproc_transaction_begin)
32 {
33 if (transaction) { LogMsg("safe_vproc_transaction_begin: Already have a transaction"); }
34 else transaction = vproc_transaction_begin(NULL);
35 }
36 }
37
38 void safe_vproc_transaction_end(void)
39 {
40 if (vproc_transaction_end)
41 {
42 if (transaction) { vproc_transaction_end(NULL, transaction); transaction = NULL; }
43 else LogMsg("safe_vproc_transaction_end: No current transaction");
44 }
45 }
46
47 #else
48
49 #if ! TARGET_OS_EMBEDDED
50 #include <stdio.h>
51 #include <CoreFoundation/CFString.h>
52
53 CF_EXPORT CFDictionaryRef _CFCopySystemVersionDictionary(void);
54 CF_EXPORT const CFStringRef _kCFSystemVersionBuildVersionKey;
55 #define OSXVers_10_6_SnowLeopard 10
56
57 void safe_vproc_transaction_begin(void)
58 {
59 static int majorversion = 0;
60 if (!majorversion)
61 {
62 CFDictionaryRef vers = _CFCopySystemVersionDictionary();
63 if (vers)
64 {
65 char buildver[256];
66 CFStringRef cfbuildver = CFDictionaryGetValue(vers, _kCFSystemVersionBuildVersionKey);
67 if (cfbuildver && CFStringGetCString(cfbuildver, buildver, sizeof(buildver), kCFStringEncodingUTF8))
68 sscanf(buildver, "%d", &majorversion);
69 CFRelease(vers);
70 }
71 if (!majorversion || majorversion >= OSXVers_10_6_SnowLeopard)
72 LogMsg("Compiled without vproc_transaction support");
73 }
74 }
75
76 #else
77
78 void safe_vproc_transaction_begin(void) { }
79
80 #endif
81
82 void safe_vproc_transaction_end(void) { }
83
84 #endif