1 /* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 #include <TargetConditionals.h>
24 # include <CoreFoundation/CoreFoundation.h>
25 # include <ApplicationServices/ApplicationServices.h>
29 int uv__set_process_title(const char* title) {
33 typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
34 typedef OSStatus (*LSSetApplicationInformationItemType)(int,
39 CFBundleRef launch_services_bundle;
40 LSGetCurrentApplicationASNType ls_get_current_application_asn;
41 LSSetApplicationInformationItemType ls_set_application_information_item;
42 CFStringRef* display_name_key;
43 ProcessSerialNumber psn;
45 CFStringRef display_name;
48 launch_services_bundle =
49 CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
51 if (launch_services_bundle == NULL)
54 ls_get_current_application_asn = (LSGetCurrentApplicationASNType)
55 CFBundleGetFunctionPointerForName(launch_services_bundle,
56 CFSTR("_LSGetCurrentApplicationASN"));
58 if (ls_get_current_application_asn == NULL)
61 ls_set_application_information_item = (LSSetApplicationInformationItemType)
62 CFBundleGetFunctionPointerForName(launch_services_bundle,
63 CFSTR("_LSSetApplicationInformationItem"));
65 if (ls_set_application_information_item == NULL)
68 display_name_key = CFBundleGetDataPointerForName(launch_services_bundle,
69 CFSTR("_kLSDisplayNameKey"));
71 if (display_name_key == NULL || *display_name_key == NULL)
74 /* Force the process manager to initialize. */
75 GetCurrentProcess(&psn);
77 display_name = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
78 asn = ls_get_current_application_asn();
79 err = ls_set_application_information_item(-2, /* Magic value. */
85 return (err == noErr) ? 0 : -1;
86 #endif /* !TARGET_OS_IPHONE */