Пример #1
0
int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
  return -1;
#else
  typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
  typedef OSStatus (*LSSetApplicationInformationItemType)(int,
                                                          CFTypeRef,
                                                          CFStringRef,
                                                          CFStringRef,
                                                          CFDictionaryRef*);
  CFBundleRef launch_services_bundle;
  LSGetCurrentApplicationASNType ls_get_current_application_asn;
  LSSetApplicationInformationItemType ls_set_application_information_item;
  CFStringRef* display_name_key;
  ProcessSerialNumber psn;
  CFTypeRef asn;
  CFStringRef display_name;
  OSStatus err;

  launch_services_bundle =
      CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));

  if (launch_services_bundle == NULL)
    return -1;

  ls_get_current_application_asn = (LSGetCurrentApplicationASNType)
      CFBundleGetFunctionPointerForName(launch_services_bundle,
                                        CFSTR("_LSGetCurrentApplicationASN"));

  if (ls_get_current_application_asn == NULL)
    return -1;

  ls_set_application_information_item = (LSSetApplicationInformationItemType)
      CFBundleGetFunctionPointerForName(launch_services_bundle,
                                        CFSTR("_LSSetApplicationInformationItem"));

  if (ls_set_application_information_item == NULL)
    return -1;

  display_name_key = CFBundleGetDataPointerForName(launch_services_bundle,
                                                   CFSTR("_kLSDisplayNameKey"));

  if (display_name_key == NULL || *display_name_key == NULL)
    return -1;

  /* Force the process manager to initialize. */
  GetCurrentProcess(&psn);

  display_name = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
  asn = ls_get_current_application_asn();
  err = ls_set_application_information_item(-2,  /* Magic value. */
                                            asn,
                                            *display_name_key,
                                            display_name,
                                            NULL);

  return (err == noErr) ? 0 : -1;
#endif  /* !TARGET_OS_IPHONE */
}
void CFBundleGetDataPointersForNames(CFBundleRef bundle, CFArrayRef symbolNames, void *stbl[]) {
    SInt32 i, c;
    
    if (!stbl) return;
    
    c = CFArrayGetCount(symbolNames);
    for (i = 0; i < c; i++) stbl[i] = CFBundleGetDataPointerForName(bundle, (CFStringRef)CFArrayGetValueAtIndex(symbolNames, i));
}
Пример #3
0
/*ARGSUSED*/
static long
krb5int_get_plugin_sym (struct plugin_file_handle *h, 
                        const char *csymname, int isfunc, void **ptr,
			struct errinfo *ep)
{
    long err = 0;
    void *sym = NULL;
    
#if USE_DLOPEN
    if (!err && !sym && (h->dlhandle != NULL)) {
        /* XXX Do we need to add a leading "_" to the symbol name on any
        modern platforms?  */
        sym = dlsym (h->dlhandle, csymname);
        if (sym == NULL) {
            const char *e = dlerror (); /* XXX copy and save away */
            Tprintf ("dlsym(%s): %s\n", csymname, e);
            err = ENOENT; /* XXX */
	    krb5int_set_error(ep, err, "%s", e);
        }
    }
#endif
    
#if USE_CFBUNDLE
    if (!err && !sym && (h->bundle != NULL)) {
        CFStringRef cfsymname = NULL;
        
        if (!err) {
            cfsymname = CFStringCreateWithCString (kCFAllocatorDefault, csymname, 
                                                   kCFStringEncodingASCII);
            if (cfsymname == NULL) { err = ENOMEM; }
        }
        
        if (!err) {
            if (isfunc) {
                sym = CFBundleGetFunctionPointerForName (h->bundle, cfsymname);
            } else {
                sym = CFBundleGetDataPointerForName (h->bundle, cfsymname);
            }
            if (sym == NULL) { err = ENOENT; }  /* XXX */       
        }
        
        if (cfsymname != NULL) { CFRelease (cfsymname); }
    }
#endif
    
    if (!err && (sym == NULL)) {
        err = ENOENT;  /* unimplemented */
    }
    
    if (!err) {
        *ptr = sym;
    }
    
    return err;
}
Пример #4
0
int printOnOSXFormat(char * string,char *format) {
	CFBundleRef bundle;
	int(*fprintf_ptr)(FILE *stream, const char *format, ...) = NULL;
	int(*fcnFlush_ptr)(FILE *stream) = NULL;
	void* fcn_ptr = NULL;
	void* fcnFlushx_ptr = NULL;
	OSErr	err;
	FILE* stderr_ptr = NULL;
	void* __sf_ptr = NULL;
	
	err = LoadFrameworkBundle( CFSTR("System.framework"), &bundle );

	fcn_ptr = CFBundleGetFunctionPointerForName(bundle, CFSTR("fprintf"));
	fcnFlushx_ptr = CFBundleGetFunctionPointerForName(bundle, CFSTR("fflush"));
	__sf_ptr = CFBundleGetDataPointerForName(bundle, CFSTR("__sF"));
	
	if(fcn_ptr) {
	   /* cast it */
	   fprintf_ptr = ( int(*)(FILE *stream, const char *format, ...) ) fcn_ptr;
	} else {
	   /* it failed, handle that somehow */
	   return;
	}

	if(fcnFlushx_ptr) {
	   /* cast it */
	   fcnFlush_ptr = ( int(*)(FILE *stream) ) fcnFlushx_ptr;
	} else {
	   /* it failed, handle that somehow */
	   return;
	}

	if(__sf_ptr) {
	   stderr_ptr = (FILE*) ( ((char*)__sf_ptr) + 176);
	   /* 176 = 88*2, where 88=sizeof(FILE) under BSD */
	} else {
	   /* it failed */
	   return;
	}

	fprintf_ptr(stderr_ptr, format,string);
	fcnFlush_ptr(stderr_ptr);
}
Пример #5
0
/*
 * LoadGlxBundle
 *  The Quartz mode X server needs to dynamically load the appropriate
 *  bundle before initializing GLX.
 */
static void LoadGlxBundle(void)
{
    CFBundleRef mainBundle;
    CFStringRef bundleName;
    CFURLRef    bundleURL;
    CFBundleRef glxBundle;

    // Get the main bundle for the application
    mainBundle = CFBundleGetMainBundle();

    // Choose the bundle to load
    ErrorF("Loading GLX bundle ");
    if (/*quartzUseAGL*/0) {
        bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
                                                     quartzOpenGLBundle,
                                                     kCFStringEncodingASCII,
                                                     kCFAllocatorNull);
        ErrorF("%s (using Apple's OpenGL)\n", quartzOpenGLBundle);
    } else {
        bundleName = CFSTR("glxMesa.bundle");
        CFRetain(bundleName);			// so we can release later
        ErrorF("glxMesa.bundle (using Mesa)\n");
    }

    // Look for the appropriate GLX bundle in the main bundle by name
    bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
                                        NULL, NULL);
    if (!bundleURL) {
        FatalError("Could not find GLX bundle.");
    }

    // Make a bundle instance using the URLRef
    glxBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);

    if (!CFBundleLoadExecutable(glxBundle)) {
        FatalError("Could not load GLX bundle.");
    }

    // Find the GLX init functions


    __DarwinglXMesaProvider = (void *) CFBundleGetDataPointerForName(
			       glxBundle, CFSTR("__glXMesaProvider"));

    GlxPushProvider = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxPushProvider"));

    GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxExtensionInit"));

    GlxWrapInitVisuals = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxWrapInitVisuals"));

    if (!GlxExtensionInit || !GlxWrapInitVisuals) {
        FatalError("Could not initialize GLX bundle.");
    }

    // Release the CF objects
    CFRelease(bundleName);
    CFRelease(bundleURL);
}
Пример #6
0
int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
  return -1;
#else
  typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
  typedef OSStatus (*LSSetApplicationInformationItemType)(int,
                                                          CFTypeRef,
                                                          CFStringRef,
                                                          CFStringRef,
                                                          CFDictionaryRef*);
  typedef CFDictionaryRef (*LSApplicationCheckInType)(int, CFDictionaryRef);
  typedef OSStatus (*SetApplicationIsDaemonType)(int);
  typedef void (*LSSetApplicationLaunchServicesServerConnectionStatusType)(
      uint64_t, void*);
  CFBundleRef launch_services_bundle;
  LSGetCurrentApplicationASNType ls_get_current_application_asn;
  LSSetApplicationInformationItemType ls_set_application_information_item;
  CFStringRef* display_name_key;
  CFTypeRef asn;
  CFStringRef display_name;
  OSStatus err;
  CFBundleRef hi_services_bundle;
  LSApplicationCheckInType ls_application_check_in;
  SetApplicationIsDaemonType set_application_is_daemon;
  LSSetApplicationLaunchServicesServerConnectionStatusType
      ls_set_application_launch_services_server_connection_status;

  launch_services_bundle =
      CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));

  if (launch_services_bundle == NULL)
    return -1;

  ls_get_current_application_asn = (LSGetCurrentApplicationASNType)
      CFBundleGetFunctionPointerForName(launch_services_bundle,
                                        CFSTR("_LSGetCurrentApplicationASN"));

  if (ls_get_current_application_asn == NULL)
    return -1;

  ls_set_application_information_item = (LSSetApplicationInformationItemType)
      CFBundleGetFunctionPointerForName(launch_services_bundle,
                                        CFSTR("_LSSetApplicationInformationItem"));

  if (ls_set_application_information_item == NULL)
    return -1;

  display_name_key = CFBundleGetDataPointerForName(launch_services_bundle,
                                                   CFSTR("_kLSDisplayNameKey"));

  if (display_name_key == NULL || *display_name_key == NULL)
    return -1;

  /* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
  hi_services_bundle =
      CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIServices"));
  if (hi_services_bundle == NULL)
    return -1;

  set_application_is_daemon = CFBundleGetFunctionPointerForName(
      hi_services_bundle,
      CFSTR("SetApplicationIsDaemon"));
  ls_application_check_in = CFBundleGetFunctionPointerForName(
      launch_services_bundle,
      CFSTR("_LSApplicationCheckIn"));
  ls_set_application_launch_services_server_connection_status =
      CFBundleGetFunctionPointerForName(
          launch_services_bundle,
          CFSTR("_LSSetApplicationLaunchServicesServerConnectionStatus"));
  if (set_application_is_daemon == NULL ||
      ls_application_check_in == NULL ||
      ls_set_application_launch_services_server_connection_status == NULL) {
    return -1;
  }

  if (set_application_is_daemon(1) != noErr)
    return -1;

  ls_set_application_launch_services_server_connection_status(0, NULL);

  /* Check into process manager?! */
  ls_application_check_in(-2,
                          CFBundleGetInfoDictionary(CFBundleGetMainBundle()));

  display_name = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
  asn = ls_get_current_application_asn();
  err = ls_set_application_information_item(-2,  /* Magic value. */
                                            asn,
                                            *display_name_key,
                                            display_name,
                                            NULL);

  return (err == noErr) ? 0 : -1;
#endif  /* !TARGET_OS_IPHONE */
}