Changeset 26843 in vbox
- Timestamp:
- Feb 26, 2010 12:59:51 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/darwin/RTSystemQueryDmiString-darwin.cpp
r26821 r26843 36 36 #include "internal/iprt.h" 37 37 38 #include <iprt/assert.h> 38 39 #include <iprt/err.h> 39 #include <iprt/ assert.h>40 #include <iprt/mem.h> 40 41 #include <iprt/string.h> 41 42 … … 43 44 #include <IOKit/IOKitLib.h> 44 45 46 47 /******************************************************************************* 48 * Defined Constants And Macros * 49 *******************************************************************************/ 45 50 #define IOCLASS_PLATFORMEXPERTDEVICE "IOPlatformExpertDevice" 46 51 #define PROP_PRODUCT_NAME "product-name" … … 48 53 #define PROP_PRODUCT_SERIAL "IOPlatformSerialNumber" 49 54 #define PROP_PRODUCT_UUID "IOPlatformUUID" 55 50 56 51 57 RTDECL(int) RTSystemQueryDmiString(RTSYSDMISTR enmString, char *pszBuf, size_t cbBuf) … … 80 86 return VERR_NOT_SUPPORTED; 81 87 88 /* IOServiceGetMatchingServices will always consume ClassToMatch. */ 82 89 io_iterator_t Iterator; 83 90 kr = IOServiceGetMatchingServices(MasterPort, ClassToMatch, &Iterator); … … 92 99 || enmString == RTSYSDMISTR_PRODUCT_VERSION) 93 100 { 94 CFDataRef DataRef = (CFDataRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef, kCFAllocatorDefault, kNilOptions); 101 CFDataRef DataRef = (CFDataRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef, 102 kCFAllocatorDefault, kNilOptions); 95 103 if (DataRef) 96 104 { 97 size_t cbData = CFDataGetLength(DataRef); 98 const uint8_t *pu8Data = CFDataGetBytePtr(DataRef); 99 memcpy(pszBuf, pu8Data, RT_MIN(cbData, cbBuf)); 100 pszBuf[RT_MIN(cbData + 1, cbBuf)] = '\0'; 101 rc = VINF_SUCCESS; 105 size_t cbData = CFDataGetLength(DataRef); 106 const char *pchData = (const char *)CFDataGetBytePtr(DataRef); 107 rc = RTStrCopyEx(pszBuf, cbBuf, pchData, cbData); 108 CFRelease(DataRef); 102 109 break; 103 110 } … … 105 112 else 106 113 { 107 CFStringRef StringRef = (CFStringRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef, kCFAllocatorDefault, kNilOptions); 114 CFStringRef StringRef = (CFStringRef)IORegistryEntryCreateCFProperty(ServiceObject, PropStringRef, 115 kCFAllocatorDefault, kNilOptions); 108 116 if (StringRef) 109 117 { 110 Boolean res = CFStringGetCString(StringRef, pszBuf, cbBuf, kCFStringEncodingASCII); 111 rc = res == TRUE ? VINF_SUCCESS : VERR_NOT_SUPPORTED; 118 Boolean fRc = CFStringGetCString(StringRef, pszBuf, cbBuf, kCFStringEncodingUTF8); 119 if (fRc) 120 rc = VINF_SUCCESS; 121 else 122 { 123 CFIndex cwc = CFStringGetLength(StringRef); 124 size_t cbTmp = cwc + 1; 125 char *pszTmp = (char *)RTMemTmpAlloc(cbTmp); 126 int cTries = 1; 127 while ( pszTmp 128 && (fRc = CFStringGetCString(StringRef, pszTmp, cbTmp, kCFStringEncodingUTF8)) == FALSE 129 && cTries++ < 4) 130 { 131 RTMemTmpFree(pszTmp); 132 cbTmp *= 2; 133 pszTmp = (char *)RTMemTmpAlloc(cbTmp); 134 } 135 if (fRc) 136 rc = RTStrCopy(pszBuf, cbBuf, pszTmp); 137 else if (!pszTmp) 138 rc = VERR_NO_TMP_MEMORY; 139 else 140 rc = VERR_ACCESS_DENIED; 141 RTMemFree(pszTmp); 142 } 143 CFRelease(StringRef); 112 144 break; 113 145 } … … 119 151 return rc; 120 152 } 153
Note:
See TracChangeset
for help on using the changeset viewer.