这篇教程C++ CFStringGetCString函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CFStringGetCString函数的典型用法代码示例。如果您正苦于以下问题:C++ CFStringGetCString函数的具体用法?C++ CFStringGetCString怎么用?C++ CFStringGetCString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CFStringGetCString函数的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: DoSetPermissionsOSStatus DoSetPermissions(COMMAND_PROC_ARGUMENTS) {#pragma unused (auth)#pragma unused (userData) OSStatus retval = noErr; // Pre-conditions // userData may be NULL assert(request != NULL); assert(response != NULL); // asl may be NULL // aslMsg may be NULL // Get Info from arguments and assert that it's a CFDictionaryRef CFDictionaryRef infos = CFDictionaryGetValue(request, CFSTR(kInfos)) ; assert(infos != NULL) ; assert(CFGetTypeID(infos) == CFDictionaryGetTypeID()) ; CFIndex nPaths = CFDictionaryGetCount(infos) ; CFMutableDictionaryRef errorDescriptions = CFDictionaryCreateMutable( NULL, nPaths, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ) ; CFMutableDictionaryRef originalModes = CFDictionaryCreateMutable( NULL, nPaths, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks ) ; CFIndex i ; int nSucceeded = 0 ; const void ** paths = (const void **)malloc( nPaths * sizeof(const void *)) ; const void ** modeNums = (const void **)malloc( nPaths * sizeof(const void *)) ; if ((paths != NULL) && (modeNums != NULL)) { CFDictionaryGetKeysAndValues( infos, paths, modeNums ) ; for (i=0; i<nPaths; i++) { // Process each path Boolean ok = true ; int retval ; // Get path, assert that it's a string anc convert to a C string CFStringRef path = paths[i] ; assert(CFGetTypeID(path) == CFStringGetTypeID()) ; char pathC[MAX_PATH_CHARS] ; if (ok) { ok = CFStringGetCString( path, pathC, MAX_PATH_CHARS, kCFStringEncodingASCII ) ; if (!ok) { CFDictionaryAddValue(errorDescriptions, path, CFSTR("Name too long")) ; } } // Read current permissions for path, wrap as CFNumber and add to results dictionary if (ok) { struct stat rawStats ; retval = stat(pathC, &rawStats) ; ok = (retval == 0) ; if (ok) { // rawStats.st_mode is of type mode_t which is an unsigned short. // Unfortunately, the available kCFNumberTypes don't have unsigned short. // And I have found that if I give CFNumberCreate an unsigned short and // tell it that it's an available kCFNumberType, which has more bits, // the undefined bits get encoded as garbage, changing the value. // First assigning the unsigned short to an int fixes it. int originalMode = rawStats.st_mode ; CFNumberRef fileModeCF = CFNumberCreate( NULL, kCFNumberIntType, &originalMode ) ; CFDictionaryAddValue( originalModes, path, fileModeCF) ; CFRelease(fileModeCF) ; } else { CFStringRef errString = CFStringCreateWithFormat( NULL, NULL, CFSTR("stat64 failed. errno: %d"), errno ) ; CFDictionaryAddValue(errorDescriptions, path, errString) ; CFQRelease(errString) ;//.........这里部分代码省略.........
开发者ID:dibowei,项目名称:CocoaPrivilegedHelper,代码行数:101,
示例2: sizeof//.........这里部分代码省略......... str = "T/F"; break; case kAudioUnitParameterUnit_Percent: case kAudioUnitParameterUnit_EqualPowerCrossfade: str = "%"; break; case kAudioUnitParameterUnit_Seconds: str = "Secs"; break; case kAudioUnitParameterUnit_SampleFrames: str = "Samps"; break; case kAudioUnitParameterUnit_Phase: case kAudioUnitParameterUnit_Degrees: str = "Degr."; break; case kAudioUnitParameterUnit_Hertz: str = "Hz"; break; case kAudioUnitParameterUnit_Cents: case kAudioUnitParameterUnit_AbsoluteCents: str = "Cents"; break; case kAudioUnitParameterUnit_RelativeSemiTones: str = "S-T"; break; case kAudioUnitParameterUnit_MIDINoteNumber: case kAudioUnitParameterUnit_MIDIController: str = "MIDI"; //these are inclusive, so add one value here mNumIndexedParams = short(mParamInfo.maxValue+1 - mParamInfo.minValue); break; case kAudioUnitParameterUnit_Decibels: str = "dB"; break; case kAudioUnitParameterUnit_MixerFaderCurve1: case kAudioUnitParameterUnit_LinearGain: str = "Gain"; break; case kAudioUnitParameterUnit_Pan: str = "L/R"; break; case kAudioUnitParameterUnit_Meters: str = "Mtrs"; break; case kAudioUnitParameterUnit_Octaves: str = "8ve"; break; case kAudioUnitParameterUnit_BPM: str = "BPM"; break; case kAudioUnitParameterUnit_Beats: str = "Beats"; break; case kAudioUnitParameterUnit_Milliseconds: str = "msecs"; break; case kAudioUnitParameterUnit_Ratio: str = "Ratio"; break; case kAudioUnitParameterUnit_Indexed: { propertySize = sizeof(mNamedParams); err = AudioUnitGetProperty (au, kAudioUnitProperty_ParameterValueStrings, scope, param, &mNamedParams, &propertySize); if (!err && mNamedParams) { mNumIndexedParams = CFArrayGetCount(mNamedParams); } else { //these are inclusive, so add one value here mNumIndexedParams = short(mParamInfo.maxValue+1 - mParamInfo.minValue); } str = NULL; } break; case kAudioUnitParameterUnit_CustomUnit: { CFStringRef unitName = mParamInfo.unitName; static char paramStr[256]; CFStringGetCString (unitName, paramStr, 256, kCFStringEncodingUTF8); if (mParamInfo.flags & kAudioUnitParameterFlag_CFNameRelease) CFRelease (unitName); str = paramStr; break; } case kAudioUnitParameterUnit_Generic: case kAudioUnitParameterUnit_Rate: default: str = NULL; break; } if (str) mParamTag = CFStringCreateWithCString(NULL, str, kCFStringEncodingUTF8); else mParamTag = NULL;}
开发者ID:kuolei,项目名称:CocoaSampleCode,代码行数:101,
示例3: vprintf_stderr_commonstatic void vprintf_stderr_common(const char* format, va_list args){#if USE(CF) && !OS(WINDOWS) if (strstr(format, "%@")) { CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);#if COMPILER(CLANG)#pragma clang diagnostic push#pragma clang diagnostic ignored "-Wformat-nonliteral"#endif CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);#if COMPILER(CLANG)#pragma clang diagnostic pop#endif CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8); char* buffer = (char*)malloc(length + 1); CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);#if USE(APPLE_SYSTEM_LOG) asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);#endif fputs(buffer, stderr); free(buffer); CFRelease(str); CFRelease(cfFormat); return; }#if USE(APPLE_SYSTEM_LOG) va_list copyOfArgs; va_copy(copyOfArgs, args); asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs); va_end(copyOfArgs);#endif // Fall through to write to stderr in the same manner as other platforms.#elif PLATFORM(BLACKBERRY) BBLOGV(BlackBerry::Platform::LogLevelCritical, format, args);#elif HAVE(ISDEBUGGERPRESENT) if (IsDebuggerPresent()) { size_t size = 1024; do { char* buffer = (char*)malloc(size); if (buffer == NULL) break; if (_vsnprintf(buffer, size, format, args) != -1) {#if OS(WINCE) // WinCE only supports wide chars wchar_t* wideBuffer = (wchar_t*)malloc(size * sizeof(wchar_t)); if (wideBuffer == NULL) break; for (unsigned int i = 0; i < size; ++i) { if (!(wideBuffer[i] = buffer[i])) break; } OutputDebugStringW(wideBuffer); free(wideBuffer);#else OutputDebugStringA(buffer);#endif free(buffer); break; } free(buffer); size *= 2; } while (size > 1024); }#endif#if !PLATFORM(BLACKBERRY) vfprintf(stderr, format, args);#endif}
开发者ID:CUITCHE,项目名称:JavaScriptCore-iOS,代码行数:79,
示例4: cdio_get_devices// Returns a pointer to an array of strings with the device namesstd::vector<std::string> cdio_get_devices(){ io_object_t next_media; mach_port_t master_port; kern_return_t kern_result; io_iterator_t media_iterator; CFMutableDictionaryRef classes_to_match; std::vector<std::string> drives; kern_result = IOMasterPort(MACH_PORT_NULL, &master_port); if (kern_result != KERN_SUCCESS) return drives; classes_to_match = IOServiceMatching(kIOCDMediaClass); if (classes_to_match == nullptr) return drives; CFDictionarySetValue(classes_to_match, CFSTR(kIOMediaEjectableKey), kCFBooleanTrue); kern_result = IOServiceGetMatchingServices(master_port, classes_to_match, &media_iterator); if (kern_result != KERN_SUCCESS) return drives; next_media = IOIteratorNext(media_iterator); if (next_media != 0) { CFTypeRef str_bsd_path; do { str_bsd_path = IORegistryEntryCreateCFProperty(next_media, CFSTR(kIOBSDNameKey), kCFAllocatorDefault, 0); if (str_bsd_path == nullptr) { IOObjectRelease(next_media); continue; } if (CFGetTypeID(str_bsd_path) == CFStringGetTypeID()) { size_t buf_size = CFStringGetLength((CFStringRef)str_bsd_path) * 4 + 1; char* buf = new char[buf_size]; if (CFStringGetCString((CFStringRef)str_bsd_path, buf, buf_size, kCFStringEncodingUTF8)) { // Below, by appending 'r' to the BSD node name, we indicate // a raw disk. Raw disks receive I/O requests directly and // don't go through a buffer cache. drives.push_back(std::string(_PATH_DEV "r") + buf); } delete[] buf; } CFRelease(str_bsd_path); IOObjectRelease(next_media); } while ((next_media = IOIteratorNext(media_iterator)) != 0); } IOObjectRelease(media_iterator); return drives;}
开发者ID:gamax92,项目名称:Ishiiruka,代码行数:65,
示例5: CFStringCreateWithCStringnuiHTTPResponse* nuiHTTPRequest::SendRequest(){ char* pUrl = mUrl.Export(); CFStringRef originalURLString = CFStringCreateWithCString(kCFAllocatorDefault, pUrl, kCFStringEncodingUTF8); CFStringRef preprocessedString = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, originalURLString, CFSTR(""), kCFStringEncodingUTF8); CFStringRef urlString = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, preprocessedString, NULL, NULL, kCFStringEncodingUTF8); free(pUrl); CFURLRef url = CFURLCreateWithString(kCFAllocatorDefault, urlString, NULL); CFRelease(urlString); char* pMeth = mMethod.Export(); CFStringRef method = CFStringCreateWithCString(kCFAllocatorDefault, pMeth, kCFStringEncodingUTF8); free(pMeth); CFHTTPMessageRef req = CFHTTPMessageCreateRequest(kCFAllocatorDefault, method, url, kCFHTTPVersion1_1); CFStringRef userAgentField = CFSTR("User-Agent"); CFStringRef userAgentName = CFSTR("nuiHTTP/2.0"); CFHTTPMessageSetHeaderFieldValue(req, userAgentField, userAgentName); CFRelease(userAgentField); CFRelease(userAgentName); nuiHTTPHeaderMap::const_iterator end = mHeaders.end(); for (nuiHTTPHeaderMap::const_iterator it = mHeaders.begin(); it != end; ++it) { char* pName = it->first.Export(); char* pVal = it->second.Export(); CFStringRef fieldName = CFStringCreateWithCString(kCFAllocatorDefault, pName, kCFStringEncodingUTF8); CFStringRef fieldValue = CFStringCreateWithCString(kCFAllocatorDefault, pVal, kCFStringEncodingUTF8); CFHTTPMessageSetHeaderFieldValue(req, fieldName, fieldValue); CFRelease(fieldName); CFRelease(fieldValue); delete pName; delete pVal; } CFDataRef body = NULL; if (mBody.size()) { body = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault, (UInt8*)&mBody[0], mBody.size(), kCFAllocatorNull); CFHTTPMessageSetBody(req, body); } CFReadStreamRef readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, req); CFReadStreamOpen(readStream); std::vector<char> buf; CFIndex pos = 0; CFIndex size = 0; bool cont = true; do { buf.resize(pos + 1024); size = CFReadStreamRead(readStream, (UInt8*)&buf[pos], 1024); if (size == -1) { return NULL; } else if (size == 0) { if (CFReadStreamGetStatus(readStream) == kCFStreamStatusAtEnd) cont = false; else nglThread::MsSleep(10); } pos += size; } while (cont); CFHTTPMessageRef responseHeader = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader); CFStringRef statusLine = CFHTTPMessageCopyResponseStatusLine(responseHeader); CFIndex strSize = CFStringGetLength(statusLine)+1; char* pStatus = new char[strSize]; CFStringGetCString(statusLine, pStatus, strSize, kCFStringEncodingUTF8); nglString status(pStatus); UInt32 statusCode = CFHTTPMessageGetResponseStatusCode(responseHeader); nuiHTTPResponse* pResponse = new nuiHTTPResponse(statusCode, status); pResponse->SetBody(&buf[0], pos); delete[] pStatus; CFDictionaryRef dict = CFHTTPMessageCopyAllHeaderFields(responseHeader); CFIndex valueCount = CFDictionaryGetCount(dict); const CFStringRef* pNames = new CFStringRef[valueCount]; const CFStringRef* pValues = new CFStringRef[valueCount]; CFDictionaryGetKeysAndValues(dict, (const void**)pNames, (const void**)pValues); for (CFIndex i = 0; i< valueCount; i++) { strSize = CFStringGetLength(pNames[i])+1;//.........这里部分代码省略.........
开发者ID:YetToCome,项目名称:nui3,代码行数:101,
示例6: HIDDumpElementInfo//.........这里部分代码省略......... break; } case kIOHIDElementCollectionTypeUsageModifier: { printf("type: Usage Modifier Collection, "); break; } default: { printf("type: %p Collection, ", (void *) tIOHIDElementCollectionType); break; } } // switch break; } default: { printf("type: %p, ", (void *) tIOHIDElementType); break; } } /* switch */ uint32_t usagePage = IOHIDElementGetUsagePage(inIOHIDElementRef); uint32_t usage = IOHIDElementGetUsage(inIOHIDElementRef); printf("usage: 0x%04lX:0x%04lX, ", (long unsigned int) usagePage, (long unsigned int) usage); CFStringRef tCFStringRef = HIDCopyUsageName(usagePage, usage); if (tCFStringRef) { char usageString[256] = ""; (void) CFStringGetCString(tCFStringRef, usageString, sizeof(usageString), kCFStringEncodingUTF8); printf("/"%s/", ", usageString); CFRelease(tCFStringRef); } CFStringRef nameCFStringRef = IOHIDElementGetName(inIOHIDElementRef); char buffer[256]; if ( nameCFStringRef && CFStringGetCString(nameCFStringRef, buffer, sizeof(buffer), kCFStringEncodingUTF8) ) { printf("name: %s, ", buffer); } uint32_t reportID = IOHIDElementGetReportID(inIOHIDElementRef); uint32_t reportSize = IOHIDElementGetReportSize(inIOHIDElementRef); uint32_t reportCount = IOHIDElementGetReportCount(inIOHIDElementRef); printf("report: { ID: %lu, Size: %lu, Count: %lu }, ", (long unsigned int) reportID, (long unsigned int) reportSize, (long unsigned int) reportCount); uint32_t unit = IOHIDElementGetUnit(inIOHIDElementRef); uint32_t unitExp = IOHIDElementGetUnitExponent(inIOHIDElementRef); if (unit || unitExp) { printf("unit: %lu * 10^%lu, ", (long unsigned int) unit, (long unsigned int) unitExp); } CFIndex logicalMin = IOHIDElementGetLogicalMin(inIOHIDElementRef); CFIndex logicalMax = IOHIDElementGetLogicalMax(inIOHIDElementRef); if (logicalMin != logicalMax) { printf("logical: {min: %ld, max: %ld}, ", logicalMin, logicalMax); } CFIndex physicalMin = IOHIDElementGetPhysicalMin(inIOHIDElementRef); CFIndex physicalMax = IOHIDElementGetPhysicalMax(inIOHIDElementRef); if (physicalMin != physicalMax) { printf("physical: {min: %ld, max: %ld}, ", physicalMin, physicalMax);
开发者ID:Vincent7,项目名称:CocoaSampleCode,代码行数:67,
示例7: setGourceDefaults//.........这里部分代码省略......... user_image_dir = entry->getString(); //append slash if(user_image_dir[user_image_dir.size()-1] != '/') { user_image_dir += std::string("/"); } //get jpg and png images in dir DIR *dp; struct dirent *dirp; user_image_map.clear(); if((dp = opendir(gGourceSettings.user_image_dir.c_str())) != 0) { while ((dirp = readdir(dp)) != 0) { std::string dirfile = std::string(dirp->d_name); size_t extpos = 0; if( (extpos=dirfile.rfind(".jpg")) == std::string::npos && (extpos=dirfile.rfind(".jpeg")) == std::string::npos && (extpos=dirfile.rfind(".png")) == std::string::npos) continue; std::string image_path = gGourceSettings.user_image_dir + dirfile; std::string name = dirfile.substr(0,extpos);#ifdef __APPLE__ CFMutableStringRef help = CFStringCreateMutable(kCFAllocatorDefault, 0); CFStringAppendCString(help, name.c_str(), kCFStringEncodingUTF8); CFStringNormalize(help, kCFStringNormalizationFormC); char data[4096]; CFStringGetCString(help, data, sizeof(data), kCFStringEncodingUTF8); name = data;#endif debugLog("%s => %s", name.c_str(), image_path.c_str()); user_image_map[name] = image_path; } closedir(dp); } } if((entry = gource_settings->getEntry("caption-file")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption file (filename)"); caption_file = entry->getString(); } if((entry = gource_settings->getEntry("caption-duration")) != 0) { if(!entry->hasValue()) conffile.entryException(entry, "specify caption duration (seconds)"); caption_duration = entry->getFloat(); if(caption_duration <= 0.0f) { conffile.invalidValueException(entry); } }
开发者ID:Frencil,项目名称:Gource,代码行数:67,
示例8: process_prefs// ----------------------------------------------------------------------------// process_prefs// ----------------------------------------------------------------------------int process_prefs(struct vpn_params *params){ char pathStr[MAXPATHLEN]; SCPreferencesRef prefs = 0; CFPropertyListRef servers_list; char text[512] = ""; // open the prefs file prefs = SCPreferencesCreate(0, CFSTR("vpnd"), kRASServerPrefsFileName); if (prefs == NULL) { CFStringGetCString(kRASServerPrefsFileName, pathStr, MAXPATHLEN, kCFStringEncodingMacRoman); snprintf(text, sizeof(text), "Unable to read vpnd prefs file '%s'/n", pathStr); goto fail; } // get servers list from the plist servers_list = SCPreferencesGetValue(prefs, kRASServers); if (servers_list == NULL) { snprintf(text, sizeof(text), "Could not get servers dictionary/n"); goto fail; } // retrieve the information for the given Server ID params->serverIDRef = CFStringCreateWithCString(0, params->server_id, kCFStringEncodingMacRoman); if (params->serverIDRef == NULL) { snprintf(text, sizeof(text), "Could not create CFString for server ID/n"); goto fail; } params->serverRef = CFDictionaryGetValue(servers_list, params->serverIDRef); if (params->serverRef == NULL || isDictionary(params->serverRef) == 0) { snprintf(text, sizeof(text), "Server ID '%.64s' invalid/n", params->server_id); params->serverRef = 0; goto fail; } CFRetain(params->serverRef); CFRelease(prefs); prefs = 0; // process the dictionaries if (process_server_prefs(params)) goto fail; if (process_interface_prefs(params)) goto fail; switch (params->server_type) { case SERVER_TYPE_PPP: if (ppp_process_prefs(params)) { snprintf(text, sizeof(text), "Error while reading PPP preferences/n"); goto fail; } break; case SERVER_TYPE_IPSEC: if (ipsec_process_prefs(params)) { snprintf(text, sizeof(text), "Error while reading IPSec preferences/n"); goto fail; } break; } return 0;fail: vpnlog(LOG_ERR, text[0] ? text : "Error while reading preferences/n"); if (params->serverIDRef) { CFRelease(params->serverIDRef); params->serverIDRef = 0; } if (params->serverRef) { CFRelease(params->serverRef); params->serverRef = 0; } if (prefs) CFRelease(prefs); return -1;}
开发者ID:Deanzou,项目名称:ppp,代码行数:78,
示例9: CF_PRIVATE void *_CFBundleDLLGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName) { void *result = NULL; char buff[1024]; if (CFStringGetCString(symbolName, buff, 1024, kCFStringEncodingWindowsLatin1)) result = GetProcAddress(bundle->_hModule, buff); return result;}
开发者ID:parkera,项目名称:swift-corelibs-foundation,代码行数:6,
示例10: disk_readstatic int disk_read (void){#if HAVE_IOKIT_IOKITLIB_H io_registry_entry_t disk; io_registry_entry_t disk_child; io_iterator_t disk_list; CFDictionaryRef props_dict; CFDictionaryRef stats_dict; CFDictionaryRef child_dict; CFStringRef tmp_cf_string_ref; kern_return_t status; signed long long read_ops; signed long long read_byt; signed long long read_tme; signed long long write_ops; signed long long write_byt; signed long long write_tme; int disk_major; int disk_minor; char disk_name[DATA_MAX_NAME_LEN]; char disk_name_bsd[DATA_MAX_NAME_LEN]; /* Get the list of all disk objects. */ if (IOServiceGetMatchingServices (io_master_port, IOServiceMatching (kIOBlockStorageDriverClass), &disk_list) != kIOReturnSuccess) { ERROR ("disk plugin: IOServiceGetMatchingServices failed."); return (-1); } while ((disk = IOIteratorNext (disk_list)) != 0) { props_dict = NULL; stats_dict = NULL; child_dict = NULL; /* `disk_child' must be released */ if ((status = IORegistryEntryGetChildEntry (disk, kIOServicePlane, &disk_child)) != kIOReturnSuccess) { /* This fails for example for DVD/CD drives.. */ DEBUG ("IORegistryEntryGetChildEntry (disk) failed: 0x%08x", status); IOObjectRelease (disk); continue; } /* We create `props_dict' => we need to release it later */ if (IORegistryEntryCreateCFProperties (disk, (CFMutableDictionaryRef *) &props_dict, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess) { ERROR ("disk-plugin: IORegistryEntryCreateCFProperties failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } if (props_dict == NULL) { DEBUG ("IORegistryEntryCreateCFProperties (disk) failed."); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } /* tmp_cf_string_ref doesn't need to be released. */ tmp_cf_string_ref = (CFStringRef) CFDictionaryGetValue (props_dict, CFSTR(kIOBSDNameKey)); if (!tmp_cf_string_ref) { DEBUG ("disk plugin: CFDictionaryGetValue(" "kIOBSDNameKey) failed."); CFRelease (props_dict); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } assert (CFGetTypeID (tmp_cf_string_ref) == CFStringGetTypeID ()); memset (disk_name_bsd, 0, sizeof (disk_name_bsd)); CFStringGetCString (tmp_cf_string_ref, disk_name_bsd, sizeof (disk_name_bsd), kCFStringEncodingUTF8); if (disk_name_bsd[0] == 0) { ERROR ("disk plugin: CFStringGetCString() failed."); CFRelease (props_dict); IOObjectRelease (disk_child); IOObjectRelease (disk); continue; } DEBUG ("disk plugin: disk_name_bsd = /"%s/"", disk_name_bsd); stats_dict = (CFDictionaryRef) CFDictionaryGetValue (props_dict, CFSTR (kIOBlockStorageDriverStatisticsKey));//.........这里部分代码省略.........
开发者ID:zach14c,项目名称:collectd,代码行数:101,
示例11: sizeof//.........这里部分代码省略......... dwRetVal = GetNetworkParams( fixedInfo, &ulOutBufLen ); uint8_t buf2[ulOutBufLen]; if(ERROR_BUFFER_OVERFLOW == dwRetVal) { fixedInfo = (FIXED_INFO *)buf2; } if ((dwRetVal = GetNetworkParams( fixedInfo, &ulOutBufLen )) != 0) LOG_ERROR("Call to GetNetworkParams failed. Return Value: %08lx/n", dwRetVal); else { m_DnsServers.push_back(IPv4Address(fixedInfo->DnsServerList.IpAddress.String)); int i = 1; LOG_DEBUG("Default DNS server IP #%d: %s/n", i++, fixedInfo->DnsServerList.IpAddress.String ); pIPAddr = fixedInfo->DnsServerList.Next; while ( pIPAddr ) { m_DnsServers.push_back(IPv4Address(pIPAddr->IpAddress.String)); LOG_DEBUG("Default DNS server IP #%d: %s/n", i++, pIPAddr->IpAddress.String); pIPAddr = pIPAddr -> Next; } }#elif LINUX std::string command = "nmcli dev list | grep IP4.DNS"; std::string dnsServersInfo = executeShellCommand(command); if (dnsServersInfo == "") { LOG_DEBUG("Error retrieving DNS server list: call to nmcli gave no output"); return; } std::istringstream stream(dnsServersInfo); std::string line; int i = 1; while(std::getline(stream, line)) { std::istringstream lineStream(line); std::string headline; std::string dnsIP; lineStream >> headline; lineStream >> dnsIP; IPv4Address dnsIPAddr(dnsIP); if (!dnsIPAddr.isValid()) continue; if (std::find(m_DnsServers.begin(), m_DnsServers.end(), dnsIPAddr) == m_DnsServers.end()) { m_DnsServers.push_back(dnsIPAddr); LOG_DEBUG("Default DNS server IP #%d: %s/n", i++, dnsIPAddr.toString().c_str()); } }#elif MAC_OS_X SCDynamicStoreRef dynRef = SCDynamicStoreCreate(kCFAllocatorSystemDefault, CFSTR("iked"), NULL, NULL); if (dynRef == NULL) { LOG_DEBUG("Couldn't set DNS server list: failed to retrieve SCDynamicStore"); return; } CFDictionaryRef dnsDict = (CFDictionaryRef)SCDynamicStoreCopyValue(dynRef,CFSTR("State:/Network/Global/DNS")); if (dnsDict == NULL) { LOG_DEBUG("Couldn't set DNS server list: failed to get DNS dictionary"); CFRelease(dynRef); return; } CFArrayRef serverAddresses = (CFArrayRef)CFDictionaryGetValue(dnsDict, CFSTR("ServerAddresses")); if (serverAddresses == NULL) { LOG_DEBUG("Couldn't set DNS server list: server addresses array is null"); CFRelease(dynRef); CFRelease(dnsDict); return; } CFIndex count = CFArrayGetCount(serverAddresses); for (CFIndex i = 0; i < count; i++) { CFStringRef serverAddress = (CFStringRef)CFArrayGetValueAtIndex(serverAddresses, i); if (serverAddress == NULL) continue; uint8_t buf[20]; char* serverAddressCString = (char*)buf; CFStringGetCString(serverAddress, serverAddressCString, 20, kCFStringEncodingUTF8); m_DnsServers.push_back(IPv4Address(serverAddressCString)); LOG_DEBUG("Default DNS server IP #%d: %s/n", (int)(i+1), serverAddressCString); } CFRelease(dynRef); CFRelease(dnsDict);#endif}
开发者ID:HaochuanXJTU,项目名称:PcapPlusPlus,代码行数:101,
示例12: get_device_infos//http://iphonedevwiki.net/index.php/Lockdowndvoid get_device_infos(CFMutableDictionaryRef out) { CC_SHA1_CTX sha1ctx; uint8_t udid[20]; char udid1[100]; CFStringRef serial; CFStringRef imei; CFStringRef macwifi; CFStringRef macbt; CFStringRef hw = copy_hardware_model(); if (hw != NULL) { CFDictionaryAddValue(out, CFSTR("hwModel"), hw); CFRelease(hw); } serial = copy_device_serial_number(); imei = copy_device_imei(); macwifi = copy_wifi_mac_address(); macbt = copy_bluetooth_mac_address(); CFMutableStringRef udidInput = CFStringCreateMutable(kCFAllocatorDefault, 0); if (serial != NULL) { CFStringAppend(udidInput, serial); CFDictionaryAddValue(out, CFSTR("serialNumber"), serial); CFRelease(serial); } uint64_t _ecid = 0; CFNumberRef ecid = copyNumberFromChosen(CFSTR("unique-chip-id")); if (ecid != NULL) { CFDictionaryAddValue(out, CFSTR("ECID"), ecid); } if (ecid != NULL && useNewUDID(hw)) { CFNumberGetValue(ecid, kCFNumberSInt64Type, &_ecid); CFStringAppendFormat(udidInput, NULL, CFSTR("%llu"), _ecid); } else if (imei != NULL) { CFStringAppend(udidInput, imei); CFDictionaryAddValue(out, CFSTR("imei"), imei); CFRelease(imei); } if (macwifi != NULL) { CFStringAppend(udidInput, macwifi); CFDictionaryAddValue(out, CFSTR("wifiMac"), macwifi); CFRelease(macwifi); } if (macbt != NULL) { CFStringAppend(udidInput, macbt); CFDictionaryAddValue(out, CFSTR("btMac"), macbt); CFRelease(macbt); } CFStringGetCString(udidInput, udid1, 99, kCFStringEncodingASCII); CC_SHA1_Init(&sha1ctx); CC_SHA1_Update(&sha1ctx, udid1, CFStringGetLength(udidInput)); CC_SHA1_Final(udid, &sha1ctx); CFRelease(udidInput); addHexaString(out, CFSTR("udid"), udid, 20);}
开发者ID:0bj3ct1veC,项目名称:iphone-dataprotection,代码行数:71,
示例13: GetScrapByName//-----------------------------------------------------------------------------const char* Platform::getClipboard(){ // mac clipboards can contain multiple items, // and each item can be in several differnt flavors, // such as unicode or plaintext or pdf, etc. // scan through the clipboard, and return the 1st piece of actual text. ScrapRef clip; char *retBuf = ""; OSStatus err = noErr; char *dataBuf = ""; // get a local ref to the system clipboard GetScrapByName( kScrapClipboardScrap, kScrapGetNamedScrap, &clip ); // First try to get unicode data, then try to get plain text data. Size dataSize = 0; bool plaintext = false; err = GetScrapFlavorSize(clip, kScrapFlavorTypeUnicode, &dataSize); if( err != noErr || dataSize <= 0) { Con::errorf("some error getting unicode clip"); plaintext = true; err = GetScrapFlavorSize(clip, kScrapFlavorTypeText, &dataSize); } // kick out if we don't have any data. if( err != noErr || dataSize <= 0) { Con::errorf("no data, kicking out. size = %i",dataSize); return ""; } if( err == noErr && dataSize > 0 ) { // ok, we've got something! allocate a buffer and copy it in. char buf[dataSize+1]; dMemset(buf, 0, dataSize+1); dataBuf = buf; // plain text needs no conversion. // unicode data needs to be converted to normalized utf-8 format. if(plaintext) { GetScrapFlavorData(clip, kScrapFlavorTypeText, &dataSize, &buf); retBuf = Con::getReturnBuffer(dataSize + 1); dMemcpy(retBuf,buf,dataSize); } else { GetScrapFlavorData(clip, kScrapFlavorTypeUnicode, &dataSize, &buf); // normalize CFStringRef cfBuf = CFStringCreateWithBytes(NULL, (const UInt8*)buf, dataSize, kCFStringEncodingUnicode, false); CFMutableStringRef normBuf = CFStringCreateMutableCopy(NULL, 0, cfBuf); CFStringNormalize(normBuf, kCFStringNormalizationFormC); // convert to utf-8 U32 normBufLen = CFStringGetLength(normBuf); U32 retBufLen = CFStringGetMaximumSizeForEncoding(normBufLen,kCFStringEncodingUTF8) + 1; // +1 for the null terminator retBuf = Con::getReturnBuffer(retBufLen); CFStringGetCString( normBuf, retBuf, retBufLen, kCFStringEncodingUTF8); dataSize = retBufLen; } // manually null terminate, just in case. retBuf[dataSize] = 0; } // return the data, or the empty string if we did not find any data. return retBuf;}
开发者ID:Bloodknight,项目名称:T3D-MIT-GMK-Port,代码行数:72,
示例14: vprintf_stderr_commonstatic void vprintf_stderr_common(const char* format, va_list args){#if USE(CF) && !OS(WINDOWS) if (strstr(format, "%@")) { CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);#if COMPILER(CLANG)#pragma clang diagnostic push#pragma clang diagnostic ignored "-Wformat-nonliteral"#endif CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);#if COMPILER(CLANG)#pragma clang diagnostic pop#endif CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8); char* buffer = (char*)malloc(length + 1); CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);#if USE(APPLE_SYSTEM_LOG) asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);#endif fputs(buffer, stderr); free(buffer); CFRelease(str); CFRelease(cfFormat); return; }#if USE(APPLE_SYSTEM_LOG) va_list copyOfArgs; va_copy(copyOfArgs, args); asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs); va_end(copyOfArgs);#endif // Fall through to write to stderr in the same manner as other platforms.#elif HAVE(ISDEBUGGERPRESENT) if (IsDebuggerPresent()) { size_t size = 1024; do { char* buffer = (char*)malloc(size); if (buffer == NULL) break; if (vsnprintf(buffer, size, format, args) != -1) { OutputDebugStringA(buffer); free(buffer); break; } free(buffer); size *= 2; } while (size > 1024); }#endif vfprintf(stderr, format, args);}
开发者ID:emutavchi,项目名称:WebKitForWayland,代码行数:62,
示例15: hu_XMLSearchForProductNameByVendorProductID/************************************************************************* * * hu_XMLSearchForProductNameByVendorProductID( inVendorID, inProductID, outCStr ) * * Purpose: Find an product string in the <HID_device_usage_strings.plist> resource ( XML ) file * * Inputs: inVendorID - the elements vendor ID * inProductID - the elements product ID * outCStr - address where result will be returned * * Returns: Boolean - if successful */static Boolean hu_XMLSearchForProductNameByVendorProductID(long inVendorID, long inProductID, char *outCStr) { Boolean results = FALSE; if ( !gUsageCFPropertyListRef ) { gUsageCFPropertyListRef = hu_XMLLoad( CFSTR( "HID_device_usage_strings"), CFSTR("plist") ); } if ( gUsageCFPropertyListRef ) { if ( CFDictionaryGetTypeID() == CFGetTypeID(gUsageCFPropertyListRef) ) { // first we make our vendor ID key CFStringRef vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inVendorID); if ( vendorKeyCFStringRef ) { // and use it to look up our vendor dictionary CFDictionaryRef vendorCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(gUsageCFPropertyListRef, vendorKeyCFStringRef, (const void **) &vendorCFDictionaryRef) ) { // pull our vendor name our of that dictionary CFStringRef vendorCFStringRef = NULL; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, kNameKeyCFStringRef, (const void **) &vendorCFStringRef) ) {#if FAKE_MISSING_NAMES CFRetain(vendorCFStringRef); // so we can CFRelease it later } else { vendorCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "V: %@"), vendorKeyCFStringRef);#endif } // now we make our product ID key CFStringRef productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%ld"), inProductID); if ( productKeyCFStringRef ) { // and use that key to look up our product dictionary in the vendor dictionary CFDictionaryRef productCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void **) &productCFDictionaryRef) ) { // pull our product name our of the product dictionary CFStringRef productCFStringRef = NULL; if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, kNameKeyCFStringRef, (const void **) &productCFStringRef) ) {#if FAKE_MISSING_NAMES CFRetain(productCFStringRef); // so we can CFRelease it later } else { productCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "P: %@"), kNameKeyCFStringRef);#endif } CFStringRef fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%@ %@"), vendorCFStringRef, productCFStringRef); if ( fullCFStringRef ) { // CFShow( fullCFStringRef ); results = CFStringGetCString(fullCFStringRef, outCStr, CFStringGetLength( fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingUTF8); CFRelease(fullCFStringRef); } #if FAKE_MISSING_NAMES if ( productCFStringRef ) { CFRelease(productCFStringRef); } #endif } CFRelease(productKeyCFStringRef); } #if FAKE_MISSING_NAMES if ( vendorCFStringRef ) { CFRelease(vendorCFStringRef); } #endif } CFRelease(vendorKeyCFStringRef); } } //.........这里部分代码省略.........
开发者ID:CarlKenner,项目名称:gz3doom,代码行数:101,
示例16: main//.........这里部分代码省略......... sLastReadTime = 0; memset (thrasher, numMeasures, kThrasherSize); UInt64 now = CAHostTimeBase::GetTheCurrentTime(); require_noerr (result = processor.Render (outputList.ABL(), numFrames, isSilence, &isDone, &postProcess), home); UInt64 renderTime = (CAHostTimeBase::GetTheCurrentTime() - now); if (i++ < discardResults) continue; if (!readBuf->lastInputFrames) break; Float64 renderTimeSecs = CAHostTimeBase::ConvertToNanos (renderTime - sLastReadTime) / 1.0e9; Float64 cpuTime = (renderTimeSecs / (readBuf->lastInputFrames / procFormat.mSampleRate)) * 100.; numMeasures++; totalMSqrd += (cpuTime * cpuTime); totalM += cpuTime; if (cpuTime > sMaxTime) sMaxTime = cpuTime; if (cpuTime < sMinTime) sMinTime = cpuTime; #if VERBOSE// printf ("current measure: %.2f/n", cpuTime); if (numMeasures % 5 == 0) { Float64 mean = totalM / numMeasures; // stdDev = (sum of Xsquared -((sum of X)*(sum of X)/N)) / (N-1)) Float64 stdDev = sqrt ((totalMSqrd - ((totalM * totalM) / numMeasures)) / (numMeasures-1.0)); printf ("ave: %.2f, min: %.2f, max: %.2f, stdev: %.2f, numMeasures: %ld, current: %f/n", mean, sMinTime, sMaxTime, stdDev, numMeasures, cpuTime); }#endif } delete [] thrasher; mean = totalM / numMeasures; // stdDev = (sum of Xsquared -((sum of X)*(sum of X)/N)) / (N-1)) Float64 stdDev = sqrt ((totalMSqrd - ((totalM * totalM) / numMeasures)) / (numMeasures-1.0)); printf ("ave: %.2f, min: %.2f, max: %.2f, sd: %.2f, sd / mean: %.2f%%/n", mean, sMinTime, sMaxTime, stdDev, (stdDev / mean * 100.)); } // we don't care about post-processinghome: if (result) { printf ("Exit with bad result:%ld/n", result); exit(result); } if (readBuf) { delete readBuf->readData; delete readBuf; } CFStringRef str = comp.GetCompName(); UInt32 compNameLen = CFStringGetLength (str); CFStringRef presetName = NULL; if (auPresetFile) { CFPropertyListRef dict; if (processor.AU().GetAUPreset (dict) == noErr) { presetName = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)dict, CFSTR("name")); CFRelease (dict); } } UInt32 presetLen = presetName ? CFStringGetLength(presetName) : 0; UInt32 groupID = comp.Desc().componentSubType; char* cstr = (char*)malloc (compNameLen + presetLen + 2 + 1); CFStringGetCString (str, cstr, (CFStringGetLength (str) + 1), kCFStringEncodingASCII); if (presetName) { cstr[compNameLen] = ':'; cstr[compNameLen+1] = ':'; CFStringGetCString (presetName, cstr + compNameLen + 2, (CFStringGetLength (presetName) + 1), kCFStringEncodingASCII); int len = strlen(cstr); for (int i = 0; i < len; ++i) groupID += cstr[i]; } PerfResult("AU Profile", EndianU32_NtoB(groupID), cstr, mean, "%realtime"); free (cstr); } catch (CAXException &e) { char buf[256]; printf("Error: %s (%s)/n", e.mOperation, e.FormatError(buf)); exit(1); } catch (...) { printf("An unknown error occurred/n"); exit(1); } return 0;}
开发者ID:paddymul,项目名称:TerminalcastRecord,代码行数:101,
示例17: hu_XMLSearchForElementNameByUsage/************************************************************************* * * hu_XMLSearchForElementNameByUsage( inVendorID, inProductID, inUsagePage, inUsage, outCStr ) * * Purpose: Find an element string in the <HID_device_usage_strings.plist> resource( XML ) file * * Inputs: inVendorID - the elements vendor ID * inProductID - the elements product ID * inUsagePage - the elements usage page * inUsage - the elements usage * outCStr - address where result will be returned * * Returns: Boolean - if successful */static Boolean hu_XMLSearchForElementNameByUsage(long inVendorID, long inProductID, long inUsagePage, long inUsage, char *outCStr) { Boolean results = FALSE; if ( !gUsageCFPropertyListRef ) { gUsageCFPropertyListRef = hu_XMLLoad( CFSTR( "HID_device_usage_strings"), CFSTR("plist") ); } if ( gUsageCFPropertyListRef ) { if ( CFDictionaryGetTypeID() == CFGetTypeID(gUsageCFPropertyListRef) ) { CFStringRef vendorKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%ld"), inVendorID); if ( vendorKeyCFStringRef ) { CFDictionaryRef vendorCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(gUsageCFPropertyListRef, vendorKeyCFStringRef, (const void **) &vendorCFDictionaryRef) ) { CFStringRef vendorCFStringRef = NULL; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, kNameKeyCFStringRef, (const void **) &vendorCFStringRef) ) { vendorCFStringRef = CFStringCreateCopy(kCFAllocatorDefault, vendorCFStringRef); } else { vendorCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("v: %ld"), inVendorID); // CFShow( vendorCFStringRef ); } CFStringRef productKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%ld"), inProductID); CFDictionaryRef productCFDictionaryRef; if ( CFDictionaryGetValueIfPresent(vendorCFDictionaryRef, productKeyCFStringRef, (const void **) &productCFDictionaryRef) ) { CFStringRef fullCFStringRef = NULL; CFStringRef productCFStringRef; if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, kNameKeyCFStringRef, (const void **) &productCFStringRef) ) { // CFShow( productCFStringRef ); } CFStringRef usageKeyCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%ld:%ld"), inUsagePage, inUsage); CFStringRef usageCFStringRef; if ( CFDictionaryGetValueIfPresent(productCFDictionaryRef, usageKeyCFStringRef, (const void **) &usageCFStringRef) ) {#if VERBOSE_ELEMENT_NAMES fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%@ %@ %@"), vendorCFStringRef, productCFStringRef, usageCFStringRef);#else fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@"), usageCFStringRef);#endif // VERBOSE_ELEMENT_NAMES // CFShow( usageCFStringRef ); } #if FAKE_MISSING_NAMES else { fullCFStringRef = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR( "%@ %@ # %@"), vendorCFStringRef, productCFStringRef, usageKeyCFStringRef); }#endif // FAKE_MISSING_NAMES if ( fullCFStringRef ) { // CFShow( fullCFStringRef ); results = CFStringGetCString(fullCFStringRef, outCStr, CFStringGetLength( fullCFStringRef) * sizeof(UniChar) + 1, kCFStringEncodingUTF8); CFRelease(fullCFStringRef); } CFRelease(usageKeyCFStringRef); } if ( vendorCFStringRef ) { CFRelease(vendorCFStringRef); } CFRelease(productKeyCFStringRef); } CFRelease(vendorKeyCFStringRef); }//.........这里部分代码省略.........
开发者ID:CarlKenner,项目名称:gz3doom,代码行数:101,
示例18: mainint main(int argc, char **argv){ nsresult rv; char *lastSlash; char iniPath[MAXPATHLEN]; char greDir[MAXPATHLEN]; bool greFound = false; CFBundleRef appBundle = CFBundleGetMainBundle(); if (!appBundle) return 1; CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(appBundle); if (!resourcesURL) return 1; CFURLRef absResourcesURL = CFURLCopyAbsoluteURL(resourcesURL); CFRelease(resourcesURL); if (!absResourcesURL) return 1; CFURLRef iniFileURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorDefault, absResourcesURL, CFSTR("application.ini"), false); CFRelease(absResourcesURL); if (!iniFileURL) return 1; CFStringRef iniPathStr = CFURLCopyFileSystemPath(iniFileURL, kCFURLPOSIXPathStyle); CFRelease(iniFileURL); if (!iniPathStr) return 1; CFStringGetCString(iniPathStr, iniPath, sizeof(iniPath), kCFStringEncodingUTF8); CFRelease(iniPathStr); printf("iniPath = %s/n", iniPath); //////////////////////////////////////// if (!getExePath(greDir)) { return 1; } /*if (!getFrameworkPath(greDir)) { return 1; }*/ /*if (realpath(tmpPath, greDir)) { greFound = true; }*/ printf("greDir = %s/n", greDir); if (access(greDir, R_OK | X_OK) == 0) greFound = true; if (!greFound) { printf("Could not find the Mozilla runtime./n"); return 1; } rv = XPCOMGlueStartup(greDir); if (NS_FAILED(rv)) { printf("Couldn't load XPCOM./n"); return 1; } printf("Glue startup OK./n"); ///////////////////////////////////////////////////// static const nsDynamicFunctionLoad kXULFuncs[] = { { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, { "XRE_main", (NSFuncPtr*) &XRE_main }, { nullptr, nullptr } }; rv = XPCOMGlueLoadXULFunctions(kXULFuncs); if (NS_FAILED(rv)) { printf("Couldn't load XRE functions./n"); return 1; } NS_LogInit(); int retval; nsXREAppData *pAppData = NULL; { nsCOMPtr<nsIFile> iniFile; // nsIFile *pIniFile; rv = NS_NewNativeLocalFile(nsDependentCString(iniPath), PR_FALSE, getter_AddRefs(iniFile)); //&pIniFile);//.........这里部分代码省略.........
开发者ID:CueMol,项目名称:cuemol2,代码行数:101,
示例19: HIDGetDeviceInfostatic voidHIDGetDeviceInfo(io_object_t hidDevice, CFMutableDictionaryRef hidProperties, recDevice * pDevice){ CFMutableDictionaryRef usbProperties = 0; io_registry_entry_t parent1, parent2; /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties */ if ((KERN_SUCCESS == IORegistryEntryGetParentEntry(hidDevice, kIOServicePlane, &parent1)) && (KERN_SUCCESS == IORegistryEntryGetParentEntry(parent1, kIOServicePlane, &parent2)) && (KERN_SUCCESS == IORegistryEntryCreateCFProperties(parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) { if (usbProperties) { CFTypeRef refCF = 0; /* get device info * try hid dictionary first, if fail then go to usb dictionary */ /* get product name */ refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductKey)); if (!refCF) refCF = CFDictionaryGetValue(usbProperties, CFSTR("USB Product Name")); if (refCF) { if (!CFStringGetCString (refCF, pDevice->product, 256, CFStringGetSystemEncoding())) SDL_SetError ("CFStringGetCString error retrieving pDevice->product."); } /* get usage page and usage */ refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usagePage)) SDL_SetError ("CFNumberGetValue error retrieving pDevice->usagePage."); refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); if (refCF) if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->usage)) SDL_SetError ("CFNumberGetValue error retrieving pDevice->usage."); } refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDVendorIDKey)); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->guid.data[0])) SDL_SetError ("CFNumberGetValue error retrieving pDevice->guid."); } refCF = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDProductIDKey)); if (refCF) { if (!CFNumberGetValue (refCF, kCFNumberLongType, &pDevice->guid.data[8])) SDL_SetError ("CFNumberGetValue error retrieving pDevice->guid[8]."); } if (NULL == refCF) { /* get top level element HID usage page or usage */ /* use top level element instead */ CFTypeRef refCFTopElement = 0; refCFTopElement = CFDictionaryGetValue(hidProperties, CFSTR(kIOHIDElementKey)); { /* refCFTopElement points to an array of element dictionaries */ CFRange range = { 0, CFArrayGetCount(refCFTopElement) }; CFArrayApplyFunction(refCFTopElement, range, HIDTopLevelElementHandler, pDevice); } } CFRelease(usbProperties); } else SDL_SetError ("IORegistryEntryCreateCFProperties failed to create usbProperties."); if (kIOReturnSuccess != IOObjectRelease(parent2)) SDL_SetError("IOObjectRelease error with parent2.");//.........这里部分代码省略.........
开发者ID:CrypticGator,项目名称:hackterm,代码行数:101,
示例20: HIDDumpDeviceInfo// utility routine to dump device infovoid HIDDumpDeviceInfo(IOHIDDeviceRef inIOHIDDeviceRef) { char cstring[256]; printf("Device: %p = { ", inIOHIDDeviceRef); char manufacturer[256] = ""; // name of manufacturer CFStringRef tCFStringRef = IOHIDDevice_GetManufacturer(inIOHIDDeviceRef); if (tCFStringRef) { (void) CFStringGetCString(tCFStringRef, manufacturer, sizeof(manufacturer), kCFStringEncodingUTF8); } char product[256] = ""; // name of product tCFStringRef = IOHIDDevice_GetProduct(inIOHIDDeviceRef); if (tCFStringRef) { (void) CFStringGetCString(tCFStringRef, product, sizeof(product), kCFStringEncodingUTF8); } printf("%s - %s, ", manufacturer, product); long vendorID = IOHIDDevice_GetVendorID(inIOHIDDeviceRef); if (vendorID) { if ( HIDGetVendorNameFromVendorID(vendorID, cstring) ) { printf(" vendorID: 0x%04lX (/"%s/"), ", vendorID, cstring); } else { printf(" vendorID: 0x%04lX, ", vendorID); } } long productID = IOHIDDevice_GetProductID(inIOHIDDeviceRef); if (productID) { if ( HIDGetProductNameFromVendorProductID(vendorID, productID, cstring) ) { printf(" productID: 0x%04lX (/"%s/"), ", productID, cstring); } else { printf(" productID: 0x%04lX, ", productID); } } uint32_t usagePage = IOHIDDevice_GetUsagePage(inIOHIDDeviceRef); uint32_t usage = IOHIDDevice_GetUsage(inIOHIDDeviceRef); if (!usagePage || !usage) { usagePage = IOHIDDevice_GetPrimaryUsagePage(inIOHIDDeviceRef); usage = IOHIDDevice_GetPrimaryUsage(inIOHIDDeviceRef); } printf("usage: 0x%04lX:0x%04lX, ", (long unsigned int) usagePage, (long unsigned int) usage); tCFStringRef = HIDCopyUsageName(usagePage, usage); if (tCFStringRef) { (void) CFStringGetCString(tCFStringRef, cstring, sizeof(cstring), kCFStringEncodingUTF8); printf("/"%s/", ", cstring); CFRelease(tCFStringRef); } tCFStringRef = IOHIDDevice_GetTransport(inIOHIDDeviceRef); if (tCFStringRef) { (void) CFStringGetCString(tCFStringRef, cstring, sizeof(cstring), kCFStringEncodingUTF8); printf("Transport: /"%s/", ", cstring); } long vendorIDSource = IOHIDDevice_GetVendorIDSource(inIOHIDDeviceRef); if (vendorIDSource) { printf("VendorIDSource: %ld, ", vendorIDSource); } long version = IOHIDDevice_GetVersionNumber(inIOHIDDeviceRef); if (version) { printf("version: %ld, ", version); } tCFStringRef = IOHIDDevice_GetSerialNumber(inIOHIDDeviceRef); if (tCFStringRef) { (void) CFStringGetCString(tCFStringRef, cstring, sizeof(cstring), kCFStringEncodingUTF8); printf("SerialNumber: /"%s/", ", cstring); } long country = IOHIDDevice_GetCountryCode(inIOHIDDeviceRef); if (country) { printf("CountryCode: %ld, ", country); } long locationID = IOHIDDevice_GetLocationID(inIOHIDDeviceRef); if (locationID) { printf("locationID: 0x%08lX, ", locationID); } #if false CFArrayRef pairs = IOHIDDevice_GetUsagePairs(inIOHIDDeviceRef); if (pairs) { CFIndex idx, cnt = CFArrayGetCount(pairs); for (idx = 0; idx < cnt; idx++) { const void * pair = CFArrayGetValueAtIndex(pairs, idx); CFShow(pair); } }#endif // if false long maxInputReportSize = IOHIDDevice_GetMaxInputReportSize(inIOHIDDeviceRef); if (maxInputReportSize) { printf("MaxInputReportSize: %ld, ", maxInputReportSize);//.........这里部分代码省略.........
开发者ID:Vincent7,项目名称:CocoaSampleCode,代码行数:101,
示例21: build_device_liststatic voidbuild_device_list(int iscapture, COREAUDIO_DeviceList ** devices, int *devCount){ OSStatus result = noErr; UInt32 size = 0; AudioObjectPropertyAddress propaddr; AudioObjectID *devs = NULL; UInt32 i = 0; UInt32 max = 0; free_device_list(devices, devCount); propaddr.mSelector = kAudioHardwarePropertyDevices; propaddr.mScope = kAudioObjectPropertyScopeGlobal; propaddr.mElement = kAudioObjectPropertyElementMaster; result = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propaddr, 0, NULL, &size); if (result != kAudioHardwareNoError) return; devs = (AudioDeviceID *) alloca(size); if (devs == NULL) return; max = size / sizeof(AudioDeviceID); *devices = (COREAUDIO_DeviceList *) SDL_malloc(max * sizeof(**devices)); if (*devices == NULL) return; result = AudioObjectGetPropertyData(kAudioObjectSystemObject, &propaddr, 0, NULL, &size, devs); if (result != kAudioHardwareNoError) return; for (i = 0; i < max; i++) { CFStringRef cfstr = NULL; char *ptr = NULL; AudioObjectID dev = devs[i]; AudioBufferList *buflist = NULL; int usable = 0; CFIndex len = 0; propaddr.mSelector = kAudioDevicePropertyStreamConfiguration; propaddr.mScope = iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; propaddr.mElement = kAudioObjectPropertyElementMaster; result = AudioObjectGetPropertyDataSize(dev, &propaddr, 0, NULL, &size); if (result != noErr) continue; buflist = (AudioBufferList *) SDL_malloc(size); if (buflist == NULL) continue; result = AudioObjectGetPropertyData(dev, &propaddr, 0, NULL, &size, buflist); if (result == noErr) { UInt32 j; for (j = 0; j < buflist->mNumberBuffers; j++) { if (buflist->mBuffers[j].mNumberChannels > 0) { usable = 1; break; } } } SDL_free(buflist); if (!usable) continue; size = sizeof(CFStringRef); propaddr.mSelector = kAudioDevicePropertyDeviceNameCFString; propaddr.mScope = iscapture ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput; propaddr.mElement = kAudioObjectPropertyElementMaster; result = AudioObjectGetPropertyData(dev, &propaddr, 0, NULL, &size, &cfstr); if (result != kAudioHardwareNoError) continue; len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstr), kCFStringEncodingUTF8); ptr = (char *) SDL_malloc(len + 1); usable = ((ptr != NULL) && (CFStringGetCString (cfstr, ptr, len + 1, kCFStringEncodingUTF8))); CFRelease(cfstr); if (usable) { len = strlen(ptr); /* Some devices have whitespace at the end...trim it. */ while ((len > 0) && (ptr[len - 1] == ' ')) { len--; } usable = (len > 0); }//.........这里部分代码省略.........
开发者ID:DAOWAce,项目名称:pcsxr,代码行数:101,
示例22: SecKeyGenerateSymmetricSecKeyRefSecKeyGenerateSymmetric(CFDictionaryRef parameters, CFErrorRef *error){ OSStatus result = paramErr; // default result for an early exit SecKeyRef key = NULL; SecKeychainRef keychain = NULL; SecAccessRef access; CFStringRef label; CFStringRef appLabel; CFStringRef appTag; CFStringRef dateLabel = NULL; CSSM_ALGORITHMS algorithm; uint32 keySizeInBits; CSSM_KEYUSE keyUsage; uint32 keyAttr = CSSM_KEYATTR_RETURN_DEFAULT; CSSM_KEYCLASS keyClass; CFTypeRef value; Boolean isPermanent; Boolean isExtractable; // verify keychain parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecUseKeychain, (const void **)&keychain)) keychain = NULL; else if (SecKeychainGetTypeID() != CFGetTypeID(keychain)) { keychain = NULL; goto errorExit; } else CFRetain(keychain); // verify permanent parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrIsPermanent, (const void **)&value)) isPermanent = false; else if (!value || (CFBooleanGetTypeID() != CFGetTypeID(value))) goto errorExit; else isPermanent = CFEqual(kCFBooleanTrue, value); if (isPermanent) { if (keychain == NULL) { // no keychain was specified, so use the default keychain result = SecKeychainCopyDefault(&keychain); } keyAttr |= CSSM_KEYATTR_PERMANENT; } // verify extractable parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrIsExtractable, (const void **)&value)) isExtractable = true; // default to extractable if value not specified else if (!value || (CFBooleanGetTypeID() != CFGetTypeID(value))) goto errorExit; else isExtractable = CFEqual(kCFBooleanTrue, value); if (isExtractable) keyAttr |= CSSM_KEYATTR_EXTRACTABLE; // verify access parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrAccess, (const void **)&access)) access = NULL; else if (SecAccessGetTypeID() != CFGetTypeID(access)) goto errorExit; // verify label parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrLabel, (const void **)&label)) label = (dateLabel = utilCopyDefaultKeyLabel()); // no label provided, so use default else if (CFStringGetTypeID() != CFGetTypeID(label)) goto errorExit; // verify application label parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrApplicationLabel, (const void **)&appLabel)) appLabel = (dateLabel) ? dateLabel : (dateLabel = utilCopyDefaultKeyLabel()); else if (CFStringGetTypeID() != CFGetTypeID(appLabel)) goto errorExit; // verify application tag parameter if (!CFDictionaryGetValueIfPresent(parameters, kSecAttrApplicationTag, (const void **)&appTag)) appTag = NULL; else if (CFStringGetTypeID() != CFGetTypeID(appTag)) goto errorExit; utilGetKeyParametersFromCFDict(parameters, &algorithm, &keySizeInBits, &keyUsage, &keyClass); if (!keychain) { // the generated key will not be stored in any keychain result = SecKeyGenerate(keychain, algorithm, keySizeInBits, 0, keyUsage, keyAttr, access, &key); } else { // we can set the label attributes on the generated key if it's a keychain item size_t labelBufLen = (label) ? (size_t)CFStringGetMaximumSizeForEncoding(CFStringGetLength(label), kCFStringEncodingUTF8) + 1 : 0; char *labelBuf = (char *)malloc(labelBufLen); size_t appLabelBufLen = (appLabel) ? (size_t)CFStringGetMaximumSizeForEncoding(CFStringGetLength(appLabel), kCFStringEncodingUTF8) + 1 : 0; char *appLabelBuf = (char *)malloc(appLabelBufLen); size_t appTagBufLen = (appTag) ? (size_t)CFStringGetMaximumSizeForEncoding(CFStringGetLength(appTag), kCFStringEncodingUTF8) + 1 : 0; char *appTagBuf = (char *)malloc(appTagBufLen); if (label && !CFStringGetCString(label, labelBuf, labelBufLen-1, kCFStringEncodingUTF8)) labelBuf[0]=0; if (appLabel && !CFStringGetCString(appLabel, appLabelBuf, appLabelBufLen-1, kCFStringEncodingUTF8)) appLabelBuf[0]=0; if (appTag && !CFStringGetCString(appTag, appTagBuf, appTagBufLen-1, kCFStringEncodingUTF8))//.........这里部分代码省略.........
开发者ID:Apple-FOSS-Mirror,项目名称:libsecurity_keychain,代码行数:101,
示例23: update_disk_stats/* * Update the counters associated with a single disk. */static voidupdate_disk_stats(struct diskstat *disk, CFDictionaryRef pproperties, CFDictionaryRef properties){ CFDictionaryRef statistics; CFStringRef name; CFNumberRef number; memset(disk, 0, sizeof(struct diskstat)); /* Get name from the drive properties */ name = (CFStringRef) CFDictionaryGetValue(pproperties, CFSTR(kIOBSDNameKey)); if(name == NULL) return; /* Not much we can do with no name */ CFStringGetCString(name, disk->name, DEVNAMEMAX, CFStringGetSystemEncoding()); /* Get the blocksize from the drive properties */ number = (CFNumberRef) CFDictionaryGetValue(pproperties, CFSTR(kIOMediaPreferredBlockSizeKey)); if(number == NULL) return; /* Not much we can do with no number */ CFNumberGetValue(number, kCFNumberSInt64Type, &disk->blocksize); /* Get the statistics from the device properties. */ statistics = (CFDictionaryRef) CFDictionaryGetValue(properties, CFSTR(kIOBlockStorageDriverStatisticsKey)); if (statistics) { number = (CFNumberRef) CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsReadsKey)); if (number) CFNumberGetValue(number, kCFNumberSInt64Type, &disk->read); number = (CFNumberRef) CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsWritesKey)); if (number) CFNumberGetValue(number, kCFNumberSInt64Type, &disk->write); number = (CFNumberRef) CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)); if (number) CFNumberGetValue(number, kCFNumberSInt64Type, &disk->read_bytes); number = (CFNumberRef) CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)); if (number) CFNumberGetValue(number, kCFNumberSInt64Type, &disk->write_bytes); number = (CFNumberRef) CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsLatentReadTimeKey)); if (number) CFNumberGetValue(number, kCFNumberSInt64Type, &disk->read_time); number = (CFNumberRef) CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsLatentWriteTimeKey)); if (number) CFNumberGetValue(number, kCFNumberSInt64Type, &disk->write_time); }}
开发者ID:goodwinos,项目名称:pcp,代码行数:65,
示例24: SetKeyLabelAndTagstatic OSStatus SetKeyLabelAndTag(SecKeyRef keyRef, CFTypeRef label, CFDataRef tag){ int numToModify = 0; if (label != NULL) { numToModify += 1; } if (tag != NULL) { numToModify += 1; } if (numToModify == 0) { return noErr; } SecKeychainAttributeList attrList; SecKeychainAttribute attributes[numToModify]; int i = 0; if (label != NULL) { if (CFStringGetTypeID() == CFGetTypeID(label)) { CFStringRef label_string = static_cast<CFStringRef>(label); attributes[i].tag = kSecKeyPrintName; attributes[i].data = (void*) CFStringGetCStringPtr(label_string, kCFStringEncodingUTF8); if (NULL == attributes[i].data) { CFIndex buffer_length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(label_string), kCFStringEncodingUTF8); attributes[i].data = alloca((size_t)buffer_length); if (NULL == attributes[i].data) { UnixError::throwMe(ENOMEM); } if (!CFStringGetCString(label_string, static_cast<char *>(attributes[i].data), buffer_length, kCFStringEncodingUTF8)) { MacOSError::throwMe(paramErr); } } attributes[i].length = strlen(static_cast<char *>(attributes[i].data)); } else if (CFDataGetTypeID() == CFGetTypeID(label)) { // 10.6 bug compatibility CFDataRef label_data = static_cast<CFDataRef>(label); attributes[i].tag = kSecKeyLabel; attributes[i].data = (void*) CFDataGetBytePtr(label_data); attributes[i].length = CFDataGetLength(label_data); } else { MacOSError::throwMe(paramErr); } i++; } if (tag != NULL) { attributes[i].tag = kSecKeyApplicationTag; attributes[i].data = (void*) CFDataGetBytePtr(tag); attributes[i].length = CFDataGetLength(tag); i++; } attrList.count = numToModify; attrList.attr = attributes; return SecKeychainItemModifyAttributesAndData((SecKeychainItemRef) keyRef, &attrList, 0, NULL);}
开发者ID:Apple-FOSS-Mirror,项目名称:libsecurity_keychain,代码行数:65,
示例25: get_darwin_localestatic gchar*get_darwin_locale (void){ static gchar *darwin_locale = NULL; CFLocaleRef locale = NULL; CFStringRef locale_language = NULL; CFStringRef locale_country = NULL; CFStringRef locale_script = NULL; CFStringRef locale_cfstr = NULL; CFIndex bytes_converted; CFIndex bytes_written; CFIndex len; int i; if (darwin_locale != NULL) return g_strdup (darwin_locale); locale = CFLocaleCopyCurrent (); if (locale) { locale_language = CFLocaleGetValue (locale, kCFLocaleLanguageCode); if (locale_language != NULL && CFStringGetBytes(locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) { len = bytes_converted + 1; locale_country = CFLocaleGetValue (locale, kCFLocaleCountryCode); if (locale_country != NULL && CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) { len += bytes_converted + 1; locale_script = CFLocaleGetValue (locale, kCFLocaleScriptCode); if (locale_script != NULL && CFStringGetBytes (locale_script, CFRangeMake (0, CFStringGetLength (locale_script)), kCFStringEncodingMacRoman, 0, FALSE, NULL, 0, &bytes_converted) > 0) { len += bytes_converted + 1; } darwin_locale = (char *) malloc (len + 1); CFStringGetBytes (locale_language, CFRangeMake (0, CFStringGetLength (locale_language)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) darwin_locale, len, &bytes_converted); darwin_locale[bytes_converted] = '-'; bytes_written = bytes_converted + 1; if (locale_script != NULL && CFStringGetBytes (locale_script, CFRangeMake (0, CFStringGetLength (locale_script)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) &darwin_locale[bytes_written], len - bytes_written, &bytes_converted) > 0) { darwin_locale[bytes_written + bytes_converted] = '-'; bytes_written += bytes_converted + 1; } CFStringGetBytes (locale_country, CFRangeMake (0, CFStringGetLength (locale_country)), kCFStringEncodingMacRoman, 0, FALSE, (UInt8 *) &darwin_locale[bytes_written], len - bytes_written, &bytes_converted); darwin_locale[bytes_written + bytes_converted] = '/0'; } } if (darwin_locale == NULL) { locale_cfstr = CFLocaleGetIdentifier (locale); if (locale_cfstr) { len = CFStringGetMaximumSizeForEncoding (CFStringGetLength (locale_cfstr), kCFStringEncodingMacRoman) + 1; darwin_locale = (char *) malloc (len); if (!CFStringGetCString (locale_cfstr, darwin_locale, len, kCFStringEncodingMacRoman)) { free (darwin_locale); CFRelease (locale); darwin_locale = NULL; return NULL; } for (i = 0; i < strlen (darwin_locale); i++) if (darwin_locale [i] == '_') darwin_locale [i] = '-'; } } CFRelease (locale); } return g_strdup (darwin_locale);}
开发者ID:Profit0004,项目名称:mono,代码行数:72,
示例26: memset//.........这里部分代码省略......... case FFSAVE_ALL: default: type = '/?/?/?/?'; creator = '/?/?/?/?'; extension = CFSTR(""); break; } // Create the dialog error = NavCreatePutFileDialog(&mNavOptions, type, creator, NULL, NULL, &navRef); if (error == noErr) { CFStringRef nameString = NULL; bool hasExtension = true; // Create a CFString of the initial file name if (!filename.empty()) nameString = CFStringCreateWithCString(NULL, filename.c_str(), kCFStringEncodingUTF8); else nameString = CFSTR("Untitled"); // Add the extension if one was not provided if (nameString && !CFStringHasSuffix(nameString, extension)) { CFStringRef tempString = nameString; hasExtension = false; nameString = CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%@"), tempString, extension); CFRelease(tempString); } // Set the name in the dialog if (nameString) { error = NavDialogSetSaveFileName(navRef, nameString); CFRelease(nameString); } else { error = paramErr; } } gViewerWindow->mWindow->beforeDialog(); // Run the dialog if (error == noErr) error = NavDialogRun(navRef); gViewerWindow->mWindow->afterDialog(); if (error == noErr) error = NavDialogGetReply(navRef, &navReply); if (navRef) NavDialogDispose(navRef); if (error == noErr && navReply.validRecord) { SInt32 count = 0; // AE indexes are 1 based... error = AECountItems(&navReply.selection, &count); if (count > 0) { // Get the FSRef to the containing folder FSRef fsRef; AEKeyword theAEKeyword; DescType typeCode; Size actualSize = 0; memset(&fsRef, 0, sizeof(fsRef)); error = AEGetNthPtr(&navReply.selection, 1, typeFSRef, &theAEKeyword, &typeCode, &fsRef, sizeof(fsRef), &actualSize); if (error == noErr) { char path[PATH_MAX]; /*Flawfinder: ignore*/ char newFileName[SINGLE_FILENAME_BUFFER_SIZE]; /*Flawfinder: ignore*/ error = FSRefMakePath(&fsRef, (UInt8*)path, PATH_MAX); if (error == noErr) { if (CFStringGetCString(navReply.saveFileName, newFileName, sizeof(newFileName), kCFStringEncodingUTF8)) { mFiles.push_back(std::string(path) + "/" + std::string(newFileName)); } else { error = paramErr; } } else { error = paramErr; } } } } return error;}
开发者ID:Xara,项目名称:Immortality,代码行数:101,
示例27: SCREENComputer//.........这里部分代码省略......... ReportSysctlError(sysctl(mib, 2, &tempInt, &tempIntSize, NULL, 0)); PsychSetStructArrayDoubleElement("ncpu", 0, (double)tempInt, hwStruct); mib[1]=HW_MEMSIZE; tempULongIntSize=sizeof(tempULongInt); tempULongInt = 0; ReportSysctlError(sysctl(mib, 2, &tempULongInt, &tempULongIntSize, NULL, 0)); PsychSetStructArrayDoubleElement("physmem", 0, (double)tempULongInt, hwStruct); mib[1]=HW_USERMEM; tempULongIntSize=sizeof(tempULongInt); tempULongInt = 0; ReportSysctlError(sysctlbyname("hw.usermem", &tempULongInt, &tempULongIntSize, NULL, 0)); PsychSetStructArrayDoubleElement("usermem", 0, (double)tempULongInt, hwStruct); mib[1]=HW_BUS_FREQ; tempULongIntSize=sizeof(tempULongInt); tempULongInt = 0; ReportSysctlError(sysctlbyname("hw.busfrequency", &tempULongInt, &tempULongIntSize, NULL, 0)); PsychSetStructArrayDoubleElement("busfreq", 0, (double)tempULongInt, hwStruct); mib[1]=HW_CPU_FREQ; tempULongIntSize=sizeof(tempULongInt); tempULongInt = 0; ReportSysctlError(sysctlbyname("hw.cpufrequency", &tempULongInt, &tempULongIntSize, NULL, 0)); PsychSetStructArrayDoubleElement("cpufreq", 0, (double)tempULongInt, hwStruct); PsychSetStructArrayStructElement("hw",0, hwStruct, majorStruct); //fill in the process user, console user and machine name in the root struct. tempCFStringRef = SCDynamicStoreCopyComputerName(NULL, NULL); if (tempCFStringRef) { stringLengthChars=(int) CFStringGetMaximumSizeForEncoding(CFStringGetLength(tempCFStringRef), kCFStringEncodingASCII); tempStrPtr=malloc(sizeof(char) * (stringLengthChars+1)); stringSuccess= CFStringGetCString(tempCFStringRef, tempStrPtr, stringLengthChars+1, kCFStringEncodingASCII); if(stringSuccess) { PsychSetStructArrayStringElement("machineName", 0, tempStrPtr, majorStruct); } else { PsychSetStructArrayStringElement("machineName", 0, "UNKNOWN! QUERY FAILED DUE TO EMPTY OR PROBLEMATIC NAME.", majorStruct); } free(tempStrPtr); CFRelease(tempCFStringRef); } else { PsychSetStructArrayStringElement("machineName", 0, "UNKNOWN! QUERY FAILED DUE TO EMPTY OR PROBLEMATIC NAME.", majorStruct); } struct passwd* thisUser = getpwuid(getuid()); if (thisUser) { PsychSetStructArrayStringElement("processUserShortName", 0, thisUser->pw_name, majorStruct); } else { PsychSetStructArrayStringElement("processUserShortName", 0, "UNKNOWN! QUERY FAILED DUE TO EMPTY OR PROBLEMATIC NAME.", majorStruct); } PsychSetStructArrayStringElement("processUserLongName", 0, PsychCocoaGetFullUsername(), majorStruct); tempCFStringRef= SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL); if (tempCFStringRef) { stringLengthChars=(int) CFStringGetMaximumSizeForEncoding(CFStringGetLength(tempCFStringRef), kCFStringEncodingASCII); tempStrPtr=malloc(sizeof(char) * (stringLengthChars+1)); stringSuccess= CFStringGetCString(tempCFStringRef, tempStrPtr, stringLengthChars+1, kCFStringEncodingASCII); if(stringSuccess) {
开发者ID:Psychtoolbox-3,项目名称:Psychtoolbox-3,代码行数:67,
示例28: PsychInitFontList//.........这里部分代码省略......... halt=ATSFontIteratorNext(fontIterator, &tempATSFontRef); if(halt==noErr){ //create a new font font structure. Set the next field to NULL as soon as we allocate the font so that if //we break with an error then we can find the end when we walk down the linked list. fontRecord=(PsychFontStructPtrType) calloc(1, sizeof(PsychFontStructType)); fontRecord->next=NULL; //Get FM and ATS font and font family references from the ATS font reference, which we get from iteration. fontRecord->fontATSRef=tempATSFontRef; fontRecord->fontFMRef=FMGetFontFromATSFontRef(fontRecord->fontATSRef); // Create CTFont from given ATSFontRef. Available since OSX 10.5 tempCTFontRef = CTFontCreateWithPlatformFont(fontRecord->fontATSRef, 0.0, NULL, NULL); if (tempCTFontRef) { // Get font family name from CTFont: CFStringRef cfFamilyName = CTFontCopyFamilyName(tempCTFontRef); // Retrieve symbolic traits of font -- the closest equivalent of the fmStyle from the // good'ol fontManager: CTFontSymbolicTraits ctTraits = CTFontGetSymbolicTraits(tempCTFontRef); // Remap new trait constants to old constants for later Screen('TextStyle') matching. fmStyle = 0; if (ctTraits & kCTFontBoldTrait) fmStyle |= 1; if (ctTraits & kCTFontItalicTrait) fmStyle |= 2; if (ctTraits & kCTFontCondensedTrait) fmStyle |= 32; if (ctTraits & kCTFontExpandedTrait) fmStyle |= 64; // CTFont no longer needed: CFRelease(tempCTFontRef); // Convert to C-String and assign: resultOK = cfFamilyName && CFStringGetCString(cfFamilyName, (char*) fontRecord->fontFMFamilyName, 255, kCFStringEncodingASCII); if(!resultOK){ if (cfFamilyName) CFRelease(cfFamilyName); if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-WARNING: In font initialization: Failed to retrieve font family name for font... Defective font?!? Skipped this entry.../n"); trouble = TRUE; continue; } // Get ATSRef for font family: fontRecord->fontFamilyATSRef = ATSFontFamilyFindFromName(cfFamilyName, kATSOptionFlagsDefault); CFRelease(cfFamilyName); } else { if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-WARNING: In font initialization: Failed to retrieve CTFontRef for font... Defective font?!? Skipped this entry.../n"); trouble = TRUE; continue; } //get the font name and set the the corresponding field of the struct if (ATSFontGetName(fontRecord->fontATSRef, kATSOptionFlagsDefault, &cfFontName)!=noErr) { if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-WARNING: In font initialization: Failed to query font name in ATSFontGetName! OS-X font handling screwed up?!? Skipped this entry.../n"); trouble = TRUE; continue; } resultOK = cfFontName && CFStringGetCString(cfFontName, (char*) fontRecord->fontFMName, 255, kCFStringEncodingASCII); if(!resultOK){ if (cfFontName) CFRelease(cfFontName); if (PsychPrefStateGet_Verbosity() > 3) printf("PTB-WARNING: In font initialization: Failed to convert fontFMName CF string to char string. Defective font?!? Skipped this entry.../n"); trouble = TRUE; continue; } CFRelease(cfFontName);
开发者ID:cchlking,项目名称:Psychtoolbox-3,代码行数:67,
注:本文中的CFStringGetCString函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CFStringGetCStringPtr函数代码示例 C++ CFStringGetBytes函数代码示例 |