30 #include <TargetConditionals.h>
33 # include <CoreFoundation/CoreFoundation.h>
34 # include <ApplicationServices/ApplicationServices.h>
42 strncpy(namebuf,
name,
sizeof(namebuf) - 1);
43 namebuf[
sizeof(namebuf) - 1] =
'\0';
45 err = pthread_setname_np(namebuf);
57 CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
60 CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
61 void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
62 void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
63 CFTypeRef (*pLSGetCurrentApplicationASN)(void);
64 OSStatus (*pLSSetApplicationInformationItem)(
int,
69 void* application_services_handle;
70 void* core_foundation_handle;
71 CFBundleRef launch_services_bundle;
72 CFStringRef* display_name_key;
73 CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
74 CFBundleRef (*pCFBundleGetMainBundle)(void);
75 CFDictionaryRef (*pLSApplicationCheckIn)(
int, CFDictionaryRef);
76 void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(
uint64_t,
82 application_services_handle = dlopen(
"/System/Library/Frameworks/"
83 "ApplicationServices.framework/"
84 "Versions/A/ApplicationServices",
85 RTLD_LAZY | RTLD_LOCAL);
86 core_foundation_handle = dlopen(
"/System/Library/Frameworks/"
87 "CoreFoundation.framework/"
88 "Versions/A/CoreFoundation",
89 RTLD_LAZY | RTLD_LOCAL);
91 if (application_services_handle == NULL || core_foundation_handle == NULL)
94 *(
void **)(&pCFStringCreateWithCString) =
95 dlsym(core_foundation_handle,
"CFStringCreateWithCString");
96 *(
void **)(&pCFBundleGetBundleWithIdentifier) =
97 dlsym(core_foundation_handle,
"CFBundleGetBundleWithIdentifier");
98 *(
void **)(&pCFBundleGetDataPointerForName) =
99 dlsym(core_foundation_handle,
"CFBundleGetDataPointerForName");
100 *(
void **)(&pCFBundleGetFunctionPointerForName) =
101 dlsym(core_foundation_handle,
"CFBundleGetFunctionPointerForName");
103 if (pCFStringCreateWithCString == NULL ||
104 pCFBundleGetBundleWithIdentifier == NULL ||
105 pCFBundleGetDataPointerForName == NULL ||
106 pCFBundleGetFunctionPointerForName == NULL) {
110 #define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
112 launch_services_bundle =
113 pCFBundleGetBundleWithIdentifier(
S(
"com.apple.LaunchServices"));
115 if (launch_services_bundle == NULL)
118 *(
void **)(&pLSGetCurrentApplicationASN) =
119 pCFBundleGetFunctionPointerForName(launch_services_bundle,
120 S(
"_LSGetCurrentApplicationASN"));
122 if (pLSGetCurrentApplicationASN == NULL)
125 *(
void **)(&pLSSetApplicationInformationItem) =
126 pCFBundleGetFunctionPointerForName(launch_services_bundle,
127 S(
"_LSSetApplicationInformationItem"));
129 if (pLSSetApplicationInformationItem == NULL)
132 display_name_key = pCFBundleGetDataPointerForName(launch_services_bundle,
133 S(
"_kLSDisplayNameKey"));
135 if (display_name_key == NULL || *display_name_key == NULL)
138 *(
void **)(&pCFBundleGetInfoDictionary) = dlsym(core_foundation_handle,
139 "CFBundleGetInfoDictionary");
140 *(
void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
141 "CFBundleGetMainBundle");
142 if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
145 *(
void **)(&pLSApplicationCheckIn) = pCFBundleGetFunctionPointerForName(
146 launch_services_bundle,
147 S(
"_LSApplicationCheckIn"));
149 if (pLSApplicationCheckIn == NULL)
152 *(
void **)(&pLSSetApplicationLaunchServicesServerConnectionStatus) =
153 pCFBundleGetFunctionPointerForName(
154 launch_services_bundle,
155 S(
"_LSSetApplicationLaunchServicesServerConnectionStatus"));
157 if (pLSSetApplicationLaunchServicesServerConnectionStatus == NULL)
160 pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
163 pLSApplicationCheckIn(-2,
164 pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
166 asn = pLSGetCurrentApplicationASN();
173 if (pLSSetApplicationInformationItem(-2,
185 if (core_foundation_handle != NULL)
186 dlclose(core_foundation_handle);
188 if (application_services_handle != NULL)
189 dlclose(application_services_handle);