当前位置: 首页>>代码示例>>C++>>正文


C++ CFStringGetLength函数代码示例

本文整理汇总了C++中CFStringGetLength函数的典型用法代码示例。如果您正苦于以下问题:C++ CFStringGetLength函数的具体用法?C++ CFStringGetLength怎么用?C++ CFStringGetLength使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CFStringGetLength函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WriteUnicodeString

// Writes a wchar_t out as length field + UTF-16 stream
void WriteUnicodeString ( std::ostream &output, const wchar_t *unicode )
{
	if ( unicode ) 
    {
#ifdef TARGET_OS_MACOSX
		// wchar_t = UTF-32, so we need to convert
		CFStringRef utf16 = CFStringCreateWithBytes(NULL, (UInt8 *)unicode, wcslen(unicode)*sizeof(wchar_t),
													kUTF32Encoding, false);
		int size = CFStringGetLength(utf16);
		WritePackedInt(output, size);
        for(int i = 0; i < size; ++ i)
        {
			WriteNetworkValue( output, CFStringGetCharacterAtIndex(utf16, i) );
        }
		
		CFRelease(utf16);
#elif defined( TARGET_OS_LINUX )
		// wchar_t is 4 byes on linux, so we need to convert
		int size = wcslen(unicode);

		size_t bufferSize = sizeof(unsigned short) * size * 2;
		size_t outBytesLeft = bufferSize;
		size_t inBytesLeft = size * sizeof(wchar_t);

		char *inBuf = (char *) unicode;
		char *buf = new char[ outBytesLeft ];
		char *outBuf = buf;

		iconv_t utf32_to_utf16 = iconv_open( "UTF16LE", "UTF32LE" );
		if( utf32_to_utf16 == (iconv_t) -1 )
		{
			perror("Failed to open iconv from UTF32LE -> UTF16LE" );
			delete[] buf;
			return;
		}
		size_t result = iconv( utf32_to_utf16, &inBuf, &inBytesLeft, &outBuf, &outBytesLeft );
		if( result == (size_t) -1 )
		{
			perror( "Failed to convert from UTF32LE -> UTF16LE" );
			delete[] buf;
			return;
		}
		iconv_close( utf32_to_utf16 );

		int bytesConverted = bufferSize - outBytesLeft;
		WritePackedInt(output, bytesConverted / sizeof(unsigned short) );
		output.write( buf, bytesConverted );
		delete[] buf;
#else
		// assume Windows and wchar_t = UTF-16
		int size = wcslen(unicode);
		WritePackedInt(output, size);
        for(int i = 0; i < size; ++ i)
        {
			WriteNetworkValue( output, unicode[i] );
        }
#endif
	}
	else 
    {
		int size = -1;
		WritePackedInt(output, size);
	}
}
开发者ID:gene9,项目名称:Darwinia-and-Multiwinia-Source-Code,代码行数:65,代码来源:network_stream.cpp

示例2: DAMountContainsArgument

Boolean DAMountContainsArgument( CFStringRef arguments, CFStringRef argument )
{
    CFBooleanRef argumentValue;
    CFBooleanRef argumentsValue;

    argumentsValue = NULL;

    if ( CFStringHasPrefix( argument, CFSTR( "no" ) ) )
    {
        argument      = CFStringCreateWithSubstring( kCFAllocatorDefault, argument, CFRangeMake( 2, CFStringGetLength( argument ) - 2 ) );
        argumentValue = kCFBooleanFalse;
    }
    else
    {
        argument      = CFRetain( argument );
        argumentValue = kCFBooleanTrue;
    }

    if ( argument )
    {
        CFArrayRef argumentList;
        CFIndex    argumentListCount;
        CFIndex    argumentListIndex;

        argumentList = CFStringCreateArrayBySeparatingStrings( kCFAllocatorDefault, arguments, CFSTR( "," ) );

        if ( argumentList )
        {
            argumentListCount = CFArrayGetCount( argumentList );

            for ( argumentListIndex = 0; argumentListIndex < argumentListCount; argumentListIndex++ )
            {
                CFStringRef compare;

                compare = CFArrayGetValueAtIndex( argumentList, argumentListIndex );

                if ( compare )
                {
                    CFBooleanRef compareValue;

                    if ( CFStringHasPrefix( compare, CFSTR( "no" ) ) )
                    {
                        compare      = CFStringCreateWithSubstring( kCFAllocatorDefault, compare, CFRangeMake( 2, CFStringGetLength( compare ) - 2 ) );
                        compareValue = kCFBooleanFalse;
                    }
                    else
                    {
                        compare      = CFRetain( compare );
                        compareValue = kCFBooleanTrue;
                    }

                    if ( compare )
                    {
                        if ( CFEqual( compare, CFSTR( FSTAB_RO ) ) )
                        {
                            CFRelease( compare );

                            compare      = CFRetain( kDAFileSystemMountArgumentNoWrite );
                            compareValue = compareValue;
                        }

                        if ( CFEqual( compare, CFSTR( FSTAB_RW ) ) )
                        {
                            CFRelease( compare );

                            compare      = CFRetain( kDAFileSystemMountArgumentNoWrite );
                            compareValue = ( compareValue == kCFBooleanTrue ) ? kCFBooleanFalse : kCFBooleanTrue;
                        }
                    }

                    if ( compare )
                    {
                        if ( CFEqual( argument, compare ) )
                        {
                            argumentsValue = compareValue;
                        }

                        CFRelease( compare );
                    }
                }
            }

            CFRelease( argumentList );
        }

        CFRelease( argument );
    }

    return ( argumentValue == argumentsValue ) ? TRUE : FALSE;
}
开发者ID:carriercomm,项目名称:osx-2,代码行数:90,代码来源:DAMount.c

示例3: 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,代码来源:HID_Name_Lookup.c

示例4: get_device_infos

//http://iphonedevwiki.net/index.php/Lockdownd
void 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,代码来源:registry.c

示例5: _CFLengthAfterDeletingPathExtension2

CF_PRIVATE CFIndex _CFLengthAfterDeletingPathExtension2(CFStringRef path) {
    CFIndex start = _CFStartOfPathExtension2(path);
    return ((0 < start) ? start : CFStringGetLength(path));
}
开发者ID:CodaFi,项目名称:swift-corelibs-foundation,代码行数:4,代码来源:CFFileUtilities.c

示例6: main

int main(int argc, char * argv[]) {
    signal(SIGINT, sigint_handler);

    bool israw = false;
    bool readstdin = false;
    char* code = NULL;
    bool usecolors = true;

    int ch;
    while ((ch = getopt(argc, argv, "nirc:t:sh")) != -1) {
        switch (ch) {
            case 'n': usecolors = false; break;
            case 'i': break;
            case 'r': israw = true; break;
            case 'c': code = optarg; break;
            case 't': recvTimeout = strtod(optarg, NULL); break;
            case 's': readstdin = true; break;
            case 'h': case '?': default:
                usage(argv[0]);
        }
    }

    if (optind != argc) usage(argv[0]);

    argc -= optind;
    argv += optind;

    CFMessagePortRef port = CFMessagePortCreateRemote(NULL, CFSTR("Hammerspoon"));

    if (!port) {
        fprintf(stderr, "error: can't access Hammerspoon; is it running with the ipc module loaded?\n");
        return 1;
    }

    CFMutableStringRef str = CFStringCreateMutable(NULL, 0);

    if (readstdin) {
        target_setprefix(str, israw);

        char buffer[BUFSIZ];
        while (fgets(buffer, BUFSIZ, stdin))
            CFStringAppendCString(str, buffer, kCFStringEncodingUTF8);

        if (ferror(stdin)) {
            perror("error reading from stdin.");
            exit(3);
        }

        target_send(port, str);
    }
    else if (code) {
        target_setprefix(str, israw);
        CFStringAppendCString(str, code, kCFStringEncodingUTF8);
        target_send(port, str);
    }
    else {
        if (usecolors)
            setupcolors();

        printf("%sHammerspoon interactive prompt.%s\n", COLOR_INITIAL, COLOR_RESET);

        while (1) {
            printf("\n%s", COLOR_INPUT);
            char* input = readline("> ");
            printf("%s", COLOR_RESET);
            if (!input) { printf("\n") ; exit(0); }
            add_history(input);

            if (!CFMessagePortIsValid(port)) {
                fprintf(stderr, "%sMessage port has become invalid.  Attempting to re-establish.%s\n", COLOR_INITIAL, COLOR_RESET);
                port = CFMessagePortCreateRemote(NULL, CFSTR("Hammerspoon"));
                if (!port) {
                    fprintf(stderr, "error: can't access Hammerspoon; is it running?\n");
                    exit(1);
                }

            }

            target_setprefix(str, israw);
            CFStringAppendCString(str, input, kCFStringEncodingUTF8);
            target_send(port, str);
            CFStringDelete(str, CFRangeMake(0, CFStringGetLength(str)));

            free(input);
        }
    }

    return 0;
}
开发者ID:BossKing10086,项目名称:hammerspoon,代码行数:89,代码来源:hs.c

示例7: appendQuotedString

CF_PRIVATE void appendQuotedString(CFMutableStringRef str, CFStringRef strToQuote) {
    char quoteChar = CFStringFindWithOptions(strToQuote, CFSTR("\""), CFRangeMake(0, CFStringGetLength(strToQuote)), 0, NULL) ? '\'' : '\"';
    CFStringAppendFormat(str, NULL, CFSTR("%c%@%c"), quoteChar, strToQuote, quoteChar);
}
开发者ID:JGiola,项目名称:swift-corelibs-foundation,代码行数:4,代码来源:CFXMLTree.c

示例8: main


//.........这里部分代码省略.........
    /* Block all these signals */
    pthread_t self = pthread_self ();
    pthread_sigmask (SIG_SETMASK, &set, NULL);

    const char *argv[i_argc + 3];
    int argc = 0;

    argv[argc++] = "--no-ignore-config";
    argv[argc++] = "--media-library";
    argv[argc++] = "--stats";

    /* overwrite system language on Mac */
#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR // TARGET_OS_MAC is unspecific
    char *lang = NULL;

    for (int i = 0; i < i_argc; i++) {
        if (!strncmp(ppsz_argv[i], "--language", 10)) {
            lang = strstr(ppsz_argv[i], "=");
            ppsz_argv++, i_argc--;
            continue;
        }
    }
    if (lang && strncmp( lang, "auto", 4 )) {
        char tmp[11];
        snprintf(tmp, 11, "LANG%s", lang);
        putenv(tmp);
    }

    if (!lang) {
        CFStringRef language;
        language = (CFStringRef)CFPreferencesCopyAppValue(CFSTR("language"),
                                                          kCFPreferencesCurrentApplication);
        if (language) {
            CFIndex length = CFStringGetLength(language) + 1;
            if (length > 0) {
                CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
                lang = (char *)malloc(maxSize);
                CFStringGetCString(language, lang, maxSize - 1, kCFStringEncodingUTF8);
            }
            if (strncmp( lang, "auto", 4 )) {
                char tmp[11];
                snprintf(tmp, 11, "LANG=%s", lang);
                putenv(tmp);
            }
            CFRelease(language);
        }
    }
#endif

    ppsz_argv++; i_argc--; /* skip executable path */

    /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
     * is the PSN - process serial number (a unique PID-ish thingie)
     * still ok for real Darwin & when run from command line
     * for example -psn_0_9306113 */
    if (i_argc >= 1 && !strncmp (*ppsz_argv, "-psn" , 4))
        ppsz_argv++, i_argc--;

    memcpy (argv + argc, ppsz_argv, i_argc * sizeof (*argv));
    argc += i_argc;
    argv[argc] = NULL;

    vlc_enable_override ();

    /* Initialize libvlc */
    libvlc_instance_t *vlc = libvlc_new (argc, argv);
开发者ID:Grade-A-Software,项目名称:Comcast-DASH-VLC,代码行数:67,代码来源:darwinvlc.c

示例9: drawPlugin

void drawPlugin(NPP instance, NPCocoaEvent* event)
{
  if (!browserUAString)
    return;

  PluginInstance* currentInstance = (PluginInstance*)(instance->pdata);
  CGContextRef cgContext = event->data.draw.context;
  if (!cgContext)
    return;

  float windowWidth = currentInstance->window.width;
  float windowHeight = currentInstance->window.height;
  
  // save the cgcontext gstate
  CGContextSaveGState(cgContext);
  
  // we get a flipped context
  CGContextTranslateCTM(cgContext, 0.0, windowHeight);
  CGContextScaleCTM(cgContext, 1.0, -1.0);
  
  // draw a gray background for the plugin
  CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
  CGContextSetGrayFillColor(cgContext, 0.5, 1.0);
  CGContextDrawPath(cgContext, kCGPathFill);
  
  // draw a black frame around the plugin
  CGContextAddRect(cgContext, CGRectMake(0, 0, windowWidth, windowHeight));
  CGContextSetGrayStrokeColor(cgContext, 0.0, 1.0);
  CGContextSetLineWidth(cgContext, 6.0);
  CGContextStrokePath(cgContext);
  
  // draw the UA string using ATSUI
  CGContextSetGrayFillColor(cgContext, 0.0, 1.0);
  ATSUStyle atsuStyle;
  ATSUCreateStyle(&atsuStyle);
  CFIndex stringLength = CFStringGetLength(browserUAString);
  UniChar* unicharBuffer = (UniChar*)malloc((stringLength + 1) * sizeof(UniChar));
  CFStringGetCharacters(browserUAString, CFRangeMake(0, stringLength), unicharBuffer);
  UniCharCount runLengths = kATSUToTextEnd;
  ATSUTextLayout atsuLayout;
  ATSUCreateTextLayoutWithTextPtr(unicharBuffer,
                                  kATSUFromTextBeginning,
                                  kATSUToTextEnd,
                                  stringLength,
                                  1,
                                  &runLengths,
                                  &atsuStyle,
                                  &atsuLayout);
  ATSUAttributeTag contextTag = kATSUCGContextTag;
  ByteCount byteSize = sizeof(CGContextRef);
  ATSUAttributeValuePtr contextATSUPtr = &cgContext;
  ATSUSetLayoutControls(atsuLayout, 1, &contextTag, &byteSize, &contextATSUPtr);
  ATSUTextMeasurement lineAscent, lineDescent;
  ATSUGetLineControl(atsuLayout,
                    kATSUFromTextBeginning,
                    kATSULineAscentTag,
                    sizeof(ATSUTextMeasurement),
                    &lineAscent,
                    &byteSize);
  ATSUGetLineControl(atsuLayout,
                    kATSUFromTextBeginning,
                    kATSULineDescentTag,
                    sizeof(ATSUTextMeasurement),
                    &lineDescent,
                    &byteSize);
  float lineHeight = FixedToFloat(lineAscent) + FixedToFloat(lineDescent);  
  ItemCount softBreakCount;
  ATSUBatchBreakLines(atsuLayout,
                      kATSUFromTextBeginning,
                      stringLength,
                      FloatToFixed(windowWidth - 10.0),
                      &softBreakCount);
  ATSUGetSoftLineBreaks(atsuLayout,
                        kATSUFromTextBeginning,
                        kATSUToTextEnd,
                        0, NULL, &softBreakCount);
  UniCharArrayOffset* softBreaks = (UniCharArrayOffset*)malloc(softBreakCount * sizeof(UniCharArrayOffset));
  ATSUGetSoftLineBreaks(atsuLayout,
                        kATSUFromTextBeginning,
                        kATSUToTextEnd,
                        softBreakCount, softBreaks, &softBreakCount);
  UniCharArrayOffset currentDrawOffset = kATSUFromTextBeginning;
  int i = 0;
  while (i < softBreakCount) {
    ATSUDrawText(atsuLayout, currentDrawOffset, softBreaks[i], FloatToFixed(5.0), FloatToFixed(windowHeight - 5.0 - (lineHeight * (i + 1.0))));
    currentDrawOffset = softBreaks[i];
    i++;
  }
  ATSUDrawText(atsuLayout, currentDrawOffset, kATSUToTextEnd, FloatToFixed(5.0), FloatToFixed(windowHeight - 5.0 - (lineHeight * (i + 1.0))));
  free(unicharBuffer);
  free(softBreaks);
  
  // restore the cgcontext gstate
  CGContextRestoreGState(cgContext);
}
开发者ID:tmm08a,项目名称:SafariCrashes,代码行数:95,代码来源:BasicPlugin.c

示例10: DAFileSystemMountWithArguments

void DAFileSystemMountWithArguments( DAFileSystemRef      filesystem,
                                     CFURLRef             device,
                                     CFURLRef             mountpoint,
                                     uid_t                userUID,
                                     gid_t                userGID,
                                     DAFileSystemCallback callback,
                                     void *               callbackContext,
                                     ... )
{
    /*
     * Mount the specified volume.  A status of 0 indicates success.  All arguments in
     * the argument list shall be of type CFStringRef.  The argument list must be NULL
     * terminated.
     */

    CFStringRef             argument       = NULL;
    va_list                 arguments;
    CFURLRef                command        = NULL;
    __DAFileSystemContext * context        = NULL;
    CFStringRef             devicePath     = NULL;
    CFStringRef             mountpointPath = NULL;
    CFMutableStringRef      options        = NULL;
    int                     status         = 0;

    /*
     * Prepare to mount the volume.
     */

    command = CFURLCreateWithFileSystemPath( kCFAllocatorDefault, CFSTR( "/sbin/mount" ), kCFURLPOSIXPathStyle, FALSE );
    if ( command == NULL )  { status = ENOTSUP; goto DAFileSystemMountErr; }

    context = malloc( sizeof( __DAFileSystemContext ) );
    if ( context == NULL )  { status = ENOMEM; goto DAFileSystemMountErr; }

    devicePath = CFURLCopyFileSystemPath( device, kCFURLPOSIXPathStyle );
    if ( devicePath == NULL )  { status = EINVAL; goto DAFileSystemMountErr; }

    mountpointPath = CFURLCopyFileSystemPath( mountpoint, kCFURLPOSIXPathStyle );
    if ( mountpointPath == NULL )  { status = EINVAL; goto DAFileSystemMountErr; }

    options = CFStringCreateMutable( kCFAllocatorDefault, 0 );
    if ( options == NULL )  { status = ENOMEM; goto DAFileSystemMountErr; }

    /*
     * Prepare the mount options.
     */

    va_start( arguments, callbackContext );

    while ( ( argument = va_arg( arguments, CFStringRef ) ) )
    {
        CFStringAppend( options, argument );
        CFStringAppend( options, CFSTR( "," ) );
    }

    va_end( arguments );

    CFStringTrim( options, CFSTR( "," ) );

    /*
     * Execute the mount command.
     */

    context->callback        = callback;
    context->callbackContext = callbackContext;

    if ( CFStringGetLength( options ) )
    {
        DACommandExecute( command,
                          kDACommandExecuteOptionDefault,
                          userUID,
                          userGID,
                          __DAFileSystemCallback,
                          context,
                          CFSTR( "-t" ),
                          DAFileSystemGetKind( filesystem ),
                          CFSTR( "-o" ),
                          options,
                          devicePath,
                          mountpointPath,
                          NULL );
    }
    else
    {
        DACommandExecute( command,
                          kDACommandExecuteOptionDefault,
                          userUID,
                          userGID,
                          __DAFileSystemCallback,
                          context,
                          CFSTR( "-t" ),
                          DAFileSystemGetKind( filesystem ),
                          devicePath,
                          mountpointPath,
                          NULL );
    }

DAFileSystemMountErr:

    if ( command        )  CFRelease( command        );
//.........这里部分代码省略.........
开发者ID:alexzhang2015,项目名称:osx-10.9,代码行数:101,代码来源:DAFileSystem.c

示例11: _IOContentsOfDirectory

// Note: as of November 2006, the matchingAbstractType isn't used at this function's only call site
static CFMutableArrayRef _IOContentsOfDirectory(CFAllocatorRef alloc, char path[CFMaxPathLength], CFURLRef base, CFStringRef matchingAbstractType) {
    CFMutableArrayRef files;
    Boolean releaseBase = FALSE;
    CFIndex pathLength = strlen(path);
    // MF:!!! Need to use four-letter type codes where appropriate.
    CFStringRef extension = (matchingAbstractType ? CFRetain(matchingAbstractType) : NULL);
    CFIndex extLen = (extension ? CFStringGetLength(extension) : 0);
    char extBuff[CFMaxPathSize];

    int fd, numread;
    long basep;
    char dirge[8192];

    if (extLen > 0) {
	// not sure what extension might contain ... currently unused
        CFStringGetBytes(extension, CFRangeMake(0, extLen), kCFStringEncodingMacRoman, 0, FALSE, extBuff, CFMaxPathSize, &extLen);
        extBuff[extLen] = '\0';	    // CFStringGetBytes set extLen to number of bytes in converted string
    }
    
    fd = open(path, O_RDONLY, 0777);
    if (fd < 0) {
        if (extension) {
            CFRelease(extension);
        }
        return NULL;
    }
    files = CFArrayCreateMutable(alloc, 0, &kCFTypeArrayCallBacks);

    while ((numread = getdirentries(fd, dirge, sizeof(dirge), &basep)) > 0) {
        struct dirent *dent;
        for (dent = (struct dirent *)dirge; dent < (struct dirent *)(dirge + numread); dent = (struct dirent *)((char *)dent + dent->d_reclen)) {
            CFURLRef fileURL;
            CFIndex nameLen;

            nameLen = dent->d_namlen;
            // skip . & ..; they cause descenders to go berserk
            if (0 == dent->d_ino /*d_fileno*/ || (dent->d_name[0] == '.' && (nameLen == 1 || (nameLen == 2 && dent->d_name[1] == '.')))) {
                continue;
            }
            if (extLen > 0) {
                // Check to see if it matches the extension we're looking for.
                if (strncmp(&(dent->d_name[nameLen - extLen]), extBuff, extLen) != 0) {
                    continue;
                }
            }
            if (base == NULL) {
                base = CFURLCreateFromFileSystemRepresentation(alloc, path, pathLength, TRUE);
                releaseBase = TRUE;
            }

            if (dent->d_type == DT_DIR || dent->d_type == DT_UNKNOWN) {
                Boolean isDir = (dent->d_type == DT_DIR);
                if (!isDir) {
                    // Ugh; must stat.
                    char subdirPath[CFMaxPathLength];
                    struct stat statBuf;
                    strncpy(subdirPath, path, pathLength);
                    subdirPath[pathLength] = '/';
                    strncpy(subdirPath + pathLength + 1, dent->d_name, nameLen);
                    subdirPath[pathLength + nameLen + 1] = '\0';
                    if (stat(subdirPath, &statBuf) == 0) {
                        isDir = ((statBuf.st_mode & S_IFMT) == S_IFDIR);
                    }
                }
                fileURL = CFURLCreateFromFileSystemRepresentationRelativeToBase(alloc, dent->d_name, nameLen, isDir, base);
            } else {
                fileURL = CFURLCreateFromFileSystemRepresentationRelativeToBase (alloc, dent->d_name, nameLen, FALSE, base);
            }
            CFArrayAppendValue(files, fileURL);
            CFRelease(fileURL);
        }
    }
    close(fd);
    if  (-1 == numread) {
        CFRelease(files);
        if (releaseBase) {
            CFRelease(base);
        }
        if (extension) {
            CFRelease(extension);
        }
        return NULL;
    }

    if (extension) {
        CFRelease(extension);
    }
    if (releaseBase) {
        CFRelease(base);
    }
    return files;
}
开发者ID:alfintatorkace,项目名称:osx-10.9-opensource,代码行数:93,代码来源:IOCFURLAccess.c

示例12: printPlist

static void printPlist(CFArrayRef plist, CFIndex indent, CFIndex maxWidth) {
    CFIndex count = CFArrayGetCount(plist);
    CFIndex ix;
    for (ix = 0; ix < count ; ++ix) {
        CFDictionaryRef prop = (CFDictionaryRef)CFArrayGetValueAtIndex(plist,
            ix);
        CFStringRef pType = (CFStringRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyType);
        CFStringRef label = (CFStringRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyLabel);
        CFStringRef llabel = (CFStringRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyLocalizedLabel);
        CFTypeRef value = (CFTypeRef)CFDictionaryGetValue(prop,
            kSecPropertyKeyValue);

        bool isSection = CFEqual(pType, kSecPropertyTypeSection);
        CFMutableStringRef line = CFStringCreateMutable(NULL, 0);
        CFIndex jx = 0;
        for (jx = 0; jx < indent; ++jx) {
            CFStringAppend(line, CFSTR("    "));
        }
        if (llabel) {
            CFStringAppend(line, llabel);
            if (!isSection) {
                for (jx = CFStringGetLength(llabel) + indent * 4;
                    jx < maxWidth; ++jx) {
                    CFStringAppend(line, CFSTR(" "));
                }
                CFStringAppend(line, CFSTR(" : "));
            }
        }
        if (CFEqual(pType, kSecPropertyTypeWarning)) {
            CFStringAppend(line, CFSTR("*WARNING* "));
            CFStringAppend(line, (CFStringRef)value);
        } else if (CFEqual(pType, kSecPropertyTypeError)) {
            CFStringAppend(line, CFSTR("*ERROR* "));
            CFStringAppend(line, (CFStringRef)value);
        } else if (CFEqual(pType, kSecPropertyTypeSuccess)) {
            CFStringAppend(line, CFSTR("*OK* "));
            CFStringAppend(line, (CFStringRef)value);
        } else if (CFEqual(pType, kSecPropertyTypeTitle)) {
            CFStringAppend(line, CFSTR("*"));
            CFStringAppend(line, (CFStringRef)value);
            CFStringAppend(line, CFSTR("*"));
        } else if (CFEqual(pType, kSecPropertyTypeSection)) {
        } else if (CFEqual(pType, kSecPropertyTypeData)) {
            CFDataRef data = (CFDataRef)value;
            CFIndex length = CFDataGetLength(data);
            if (length > 20)
                CFStringAppendFormat(line, NULL, CFSTR("[%d bytes] "), length);
            const UInt8 *bytes = CFDataGetBytePtr(data);
            for (jx = 0; jx < length; ++jx) {
                if (jx == 0)
                    CFStringAppendFormat(line, NULL, CFSTR("%02X"), bytes[jx]);
                else if (jx < 15 || length <= 20)
                    CFStringAppendFormat(line, NULL, CFSTR(" %02X"),
                        bytes[jx]);
                else {
                    CFStringAppend(line, CFSTR(" ..."));
                    break;
                }
            }
        } else if (CFEqual(pType, kSecPropertyTypeString)) {
            CFStringAppend(line, (CFStringRef)value);
        } else if (CFEqual(pType, kSecPropertyTypeDate)) {
            CFDateRef date = (CFDateRef)value;
            CFLocaleRef lc = CFLocaleCopyCurrent();
            CFDateFormatterRef df = CFDateFormatterCreate(NULL, lc, kCFDateFormatterMediumStyle, kCFDateFormatterLongStyle);
            CFStringRef ds;
            if (df) {
                CFTimeZoneRef tz = CFTimeZoneCreateWithTimeIntervalFromGMT(NULL, 0.0);
                CFDateFormatterSetProperty(df, kCFDateFormatterTimeZone, tz);
                CFRelease(tz);
                ds = CFDateFormatterCreateStringWithDate(NULL, df, date);
                CFRelease(df);
            } else {
                ds = CFStringCreateWithFormat(NULL, NULL, CFSTR("%g"), CFDateGetAbsoluteTime(date));
            }
            CFStringAppend(line, ds);
            CFRelease(ds);
            CFRelease(lc);
        } else if (CFEqual(pType, kSecPropertyTypeURL)) {
            CFURLRef url = (CFURLRef)value;
            CFStringAppend(line, CFSTR("<"));
            CFStringAppend(line, CFURLGetString(url));
            CFStringAppend(line, CFSTR(">"));
        } else {
            CFStringAppendFormat(line, NULL, CFSTR("*unknown type %@* = %@"),
            pType, value);
        }

		if (!isSection || label)
			print_line(line);
		CFRelease(line);
        if (isSection) {
            printPlist((CFArrayRef)value, indent + 1, maxWidth);
        }
    }
}
开发者ID:unofficial-opensource-apple,项目名称:Security,代码行数:99,代码来源:printCert.c

示例13: gensetup_add_clicked

pascal OSStatus
gensetup_add_clicked (EventHandlerCallRef inHandlerRef,
    EventRef inEvent, void *inUserData)
{
  TGENSETUP *gensetup_t = (TGENSETUP *) inUserData;
  DataBrowserItemID item = DBITEM_ID + 1;
  DataBrowserCallbacks dbCallbacks;
  ThemeDrawingState outState = NULL;
  UInt16 colSize[2] = { 150, 250 };
  SInt16 outBaseline;
  Point ioBound;
  CFStringRef data[2];
  Size len;
  int i = 0, j;

  if (gensetup_t)
    {
      GetThemeDrawingState (&outState);

      GetControlData (gensetup_t->key_entry, 0, kControlEditTextCFStringTag,
	  sizeof (CFStringRef), &data[0], &len);
      if (CFStringGetLength(data[0]))
	{
	  GetControlData (gensetup_t->value_entry, 0, kControlEditTextCFStringTag,
            sizeof (CFStringRef), &data[1], &len);

	  /* Try to see if the keyword already exists */
	  for (i = 0; i < DSNSETUP_nrows; i++, item++)
	    if (CFStringCompare (data[0], DSNSETUP_array[0][i],
		    0) == kCFCompareEqualTo)
	      goto done;

	  /* Install an event handler on the component databrowser */
	  dbCallbacks.version = kDataBrowserLatestCallbacks;
	  InitDataBrowserCallbacks (&dbCallbacks);
	  dbCallbacks.u.v1.itemNotificationCallback =
	      NewDataBrowserItemNotificationUPP (dsnsetup_notification_item);
          /* On Mac OS X 10.0.x : this is clientDataCallback */
	  dbCallbacks.u.v1.itemDataCallback =
	      NewDataBrowserItemDataUPP (dsnsetup_getset_item);
	  SetDataBrowserCallbacks (gensetup_t->key_list, &dbCallbacks);
	  /* Begin the draw of the data browser */
	  SetDataBrowserTarget (gensetup_t->key_list, DBITEM_ID);

          /* An update operation */
          if(i<DSNSETUP_nrows)
            {
              CFRelease (DSNSETUP_array[1][i]);
              DSNSETUP_array[1][i] = data[1];
              UpdateDataBrowserItems (gensetup_t->key_list, DBITEM_ID, 1, &item,
                GSKEYWORD_ID, kDataBrowserItemNoProperty);
            }
          else if(len)
            {
              DSNSETUP_array[0][i] = data[0];
              DSNSETUP_array[1][i] = data[1];
              AddDataBrowserItems (gensetup_t->key_list, DBITEM_ID, 1, &item,
                GSKEYWORD_ID);
              DSNSETUP_nrows++;
            }

          for(j = 0 ; j < DSNSETUP_nrows ; j++)
            {
              for(i = 0 ; i < 2 ; i++)
                {
                  GetThemeTextDimensions (DSNSETUP_array[i][j], kThemeSystemFont,
                    kThemeStateActive, false, &ioBound, &outBaseline);
                  if(colSize[i] < ioBound.h) colSize[i] = ioBound.h;
                }
            }

	  ActivateControl (gensetup_t->key_list);
	  /* Resize the columns to have a good look */
          SetDataBrowserTableViewNamedColumnWidth (gensetup_t->key_list, GSKEYWORD_ID, colSize[0] + 20);
          SetDataBrowserTableViewNamedColumnWidth (gensetup_t->key_list, GSVALUE_ID, colSize[1] + 20);
	  DrawOneControl (gensetup_t->key_list);
	  /* Remove the DataBrowser callback */
	  SetDataBrowserCallbacks (NULL, &dbCallbacks);
	}

done:
      SetControlData (gensetup_t->key_entry, 0, kControlEditTextTextTag, 0,
	  "");
      DrawOneControl (gensetup_t->key_entry);
      SetControlData (gensetup_t->value_entry, 0, kControlEditTextTextTag, 0,
	  "");
      DrawOneControl (gensetup_t->value_entry);
      DeactivateControl (DSNSETUP->bupdate);
      DrawOneControl (DSNSETUP->bupdate);
    }

  return noErr;
}
开发者ID:MavenRain,项目名称:iODBC,代码行数:93,代码来源:gensetup.c

示例14: ReadPackedInt

// Reads a length field + UTF-16 stream into a wchar_t
wchar_t *ReadUnicodeString( std::istream &input, int maxLength, const wchar_t *safeString )
{
	int size = ReadPackedInt(input);

	if ( size == -1 ) 
    {
		return NULL;
	}
    else if ( size < 0 ||
              size > maxLength )
    {        
        return newStr(safeString);        
    }    
	else 
    {
#ifdef TARGET_OS_MACOSX
		UniChar *unichars = new UniChar[size];
		wchar_t *wchars = new wchar_t[size+1];
		CFStringRef utf16;
		
		for(int i = 0; i < size; i++)
			ReadNetworkValue( input, unichars[i] );
		
		utf16 = CFStringCreateWithCharactersNoCopy(NULL, unichars, size, kCFAllocatorNull);
		CFStringGetBytes(utf16, CFRangeMake(0, CFStringGetLength(utf16)), kUTF32Encoding, '?', false,
						 (UInt8 *)wchars, (size+1)*sizeof(wchar_t), NULL);
		wchars[size] = '\x0';
		CFRelease(utf16);
		delete unichars;
		
		return wchars;
#elif defined( TARGET_OS_LINUX )
		size_t inBytesLeft = size * sizeof(unsigned short);
		char *utf16 = new char[inBytesLeft];
		input.read( utf16, inBytesLeft );

		char *inBuf = utf16;

		size_t bufferSize = size + 1;
		size_t outBytesLeft = bufferSize * 4;
		wchar_t *buf = new wchar_t[ bufferSize ];
		char *outBuf = (char *) buf;

		buf[0] = L'\0';

		iconv_t utf16_to_utf32 = iconv_open( "UTF32LE", "UTF16LE" );
		if( utf16_to_utf32 == (iconv_t) -1 )
		{
			perror( "Failed to open iconv" );
			delete[] utf16;
			return buf;
		}

		size_t result = iconv( utf16_to_utf32, &inBuf, &inBytesLeft, &outBuf, &outBytesLeft );
		iconv_close( utf16_to_utf32 );

		if( result == (size_t) -1 )
		{
			perror( "Failed to convert stream to utf32le" );
			delete[] utf16;
			return buf;
		}

		delete[] utf16;		

		buf[size] = L'\x0';
		return (wchar_t *) buf;
#else
		wchar_t *string = new wchar_t [size+1];
		for(int i = 0; i < size; i++)
			ReadNetworkValue( input, string[i] );
		string[size] = '\x0';
		return string;
#endif
	}
}
开发者ID:gene9,项目名称:Darwinia-and-Multiwinia-Source-Code,代码行数:77,代码来源:network_stream.cpp

示例15: strstr

void HTTP_Stream::parseHttpHeadersIfNeeded(UInt8 *buf, CFIndex bufSize)
{
    if (m_httpHeadersParsed) {
        return;
    }
    m_httpHeadersParsed = true;
    
    /* If the response has the "ICY 200 OK" string,
     * we are dealing with the ShoutCast protocol.
     * The HTTP headers won't be available.
     */
    std::string header;
    
    for (CFIndex k=0; k < bufSize; k++) {
        UInt8 c = buf[k];
        // Ignore non-ASCII chars
        if (c < 32 || c > 126) {
            continue;
        }
        header.push_back(c);
    }
    
    char *p = strstr(header.c_str(), "ICY 200 OK");
    
    // This is an ICY stream, don't try to parse the HTTP headers
    if (p) {
        m_icyStream = true;
        return;
    }
    
    CFHTTPMessageRef response = (CFHTTPMessageRef)CFReadStreamCopyProperty(m_readStream, kCFStreamPropertyHTTPResponseHeader);
    if (response) {
        /*
         * If the server responded with the icy-metaint header, the response
         * body will be encoded in the ShoutCast protocol.
         */
        CFStringRef icyMetaIntString = CFHTTPMessageCopyHeaderFieldValue(response, CFSTR("icy-metaint"));
        if (icyMetaIntString) {
            m_icyStream = true;
            m_icyHeadersParsed = true;
            m_icyHeadersRead = true;
            m_icyMetaDataInterval = CFStringGetIntValue(icyMetaIntString);
            CFRelease(icyMetaIntString);
        }
        
        CFStringRef contentTypeString = CFHTTPMessageCopyHeaderFieldValue(response, CFSTR("Content-Type"));
        if (contentTypeString) {
            CFIndex len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(contentTypeString), kCFStringEncodingUTF8) + 1;
            char *buf = new char[len];
            if (CFStringGetCString(contentTypeString, buf, len, kCFStringEncodingUTF8)) {
                m_contentType.append(buf);
            }
            delete[] buf;
        
            CFRelease(contentTypeString);
        }
        
        CFStringRef contentLengthString = CFHTTPMessageCopyHeaderFieldValue(response, CFSTR("Content-Length"));
        if (contentLengthString) {
            m_contentLength = CFStringGetIntValue(contentLengthString);
            
            CFRelease(contentLengthString);
        }
        
        CFRelease(response);
    }
       
    if (m_delegate) {
        m_delegate->streamIsReadyRead();
    }
}
开发者ID:akdsouza,项目名称:FreeStreamer,代码行数:71,代码来源:http_stream.cpp


注:本文中的CFStringGetLength函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。