Esempio n. 1
0
void getprocesspath(char* buffer, size_t bufferLen)
{
#if defined( OS_MACOSX )
	CFBundleRef mainBundle = CFBundleGetMainBundle();
	CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle);
	CFURLRef workingUrl = CFURLCreateCopyDeletingPathExtension(kCFAllocatorSystemDefault, bundleUrl);
	CFStringRef workingString = CFURLCopyFileSystemPath(workingUrl, kCFURLPOSIXPathStyle);
	CFMutableStringRef normalizedString = CFStringCreateMutableCopy(NULL, 0, workingString);
	CFStringGetCString(normalizedString, buffer, bufferLen - 1, kCFStringEncodingUTF8);
	CFRelease(workingUrl);
	CFRelease(workingString);
	CFRelease(normalizedString);
	CFRelease(bundleUrl);
#elif defined(__FreeBSD__)
	sysctl_get_pathname(buffer, bufferLen);
	dirname(buffer);
	strcat(buffer, "/");
#else
	int count = readlink("/proc/self/exe", buffer, bufferLen);
	if (count != -1)
	{
		buffer[count] = 0;
		dirname(buffer);
		strcat(buffer, "/");
		return;
	}
	*buffer = 0;
#endif
}
/* do a [NSString stringByDeletingPathExtension] equivalent */
CFStringRef impExpImportDeleteExtension(
	CFStringRef			fileStr)
{
	CFDataRef fileStrData = CFStringCreateExternalRepresentation(NULL, fileStr,
		kCFStringEncodingUTF8, 0);
	if(fileStrData == NULL) {
		return NULL;
	}

	CFURLRef urlRef = CFURLCreateFromFileSystemRepresentation(NULL,
		CFDataGetBytePtr(fileStrData), CFDataGetLength(fileStrData), false);
	if(urlRef == NULL) {
		CFRelease(fileStrData);
		return NULL;
	}
	CFURLRef rtnUrl = CFURLCreateCopyDeletingPathExtension(NULL, urlRef);
	CFStringRef rtnStr = NULL;
	CFRelease(urlRef);
	if(rtnUrl) {
		rtnStr = CFURLGetString(rtnUrl);
		CFRetain(rtnStr);
		CFRelease(rtnUrl);
	}
	CFRelease(fileStrData);
	return rtnStr;
}
Esempio n. 3
0
 void URL::DeletePathExtension( void )
 {
     CFURLRef url;
     
     if( this->_cfObject == NULL )
     {
         return;
     }
     
     url             = this->_cfObject;
     this->_cfObject = CFURLCreateCopyDeletingPathExtension
     (
         static_cast< CFAllocatorRef >( NULL ),
         url
     );
     
     CFRelease( url );
 }
Esempio n. 4
0
kim_error kim_os_library_get_caller_name (kim_string *out_application_name)
{
    kim_error err = KIM_NO_ERROR;
    kim_string name = NULL;
    CFBundleRef bundle = CFBundleGetMainBundle ();
    CFStringRef cfname = NULL;

    if (!err && !out_application_name) { err = check_error (KIM_NULL_PARAMETER_ERR); }

    if (!err && bundle) {
        cfname = CFBundleGetValueForInfoDictionaryKey (bundle,
                                                       kCFBundleNameKey);

        if (!cfname || CFGetTypeID (cfname) != CFStringGetTypeID ()) {
            cfname = CFBundleGetValueForInfoDictionaryKey (bundle,
                                                           kCFBundleExecutableKey);
        }

        if (cfname) {
            cfname = CFStringCreateCopy (kCFAllocatorDefault, cfname);
        }
    }

    if (!err && !cfname) {
        kim_string path = NULL;
        CFURLRef cfpath = NULL;
        CFURLRef cfpathnoext = NULL;

        err = kim_os_library_get_application_path (&path);

        if (!err) {
            cfpath = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault,
                                                              (const UInt8 *) path,
                                                              strlen (path),
                                                              0);

            if (cfpath) {
                cfpathnoext = CFURLCreateCopyDeletingPathExtension (kCFAllocatorDefault,
                                                                    cfpath);
            }

            if (cfpathnoext) {
                cfname = CFURLCopyLastPathComponent (cfpathnoext);
            } else {
                cfname = CFURLCopyLastPathComponent (cfpath);
            }
        }

        if (cfpathnoext) { CFRelease (cfpathnoext); }
        if (cfpath     ) { CFRelease (cfpath); }
        kim_string_free (&path);
    }

    if (!err && cfname) {
        err = kim_os_string_create_from_cfstring (&name, cfname);
    }

    if (!err) {
        *out_application_name = name;
        name = NULL;

    }

    if (cfname) { CFRelease (cfname); }
    kim_string_free (&name);

    return check_error (err);
}