Changeset 9738 in vbox
- Timestamp:
- Jun 16, 2008 10:38:49 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/com/Guid.h
r9332 r9738 103 103 } 104 104 105 bool isEmpty() const { return ::RTUuidIsNull (&uuid) != 0; }105 bool isEmpty() const { return ::RTUuidIsNull (&uuid); } 106 106 operator bool() const { return !isEmpty(); } 107 107 … … 173 173 static bool isEmpty (const GUID &guid) 174 174 { 175 return ::RTUuidIsNull ((PRTUUID) &guid) != 0;175 return ::RTUuidIsNull ((PRTUUID) &guid); 176 176 } 177 177 -
trunk/include/iprt/uuid.h
r8245 r9738 63 63 * @param pUuid uuid to check. 64 64 */ 65 RTDECL( int) RTUuidIsNull(PCRTUUID pUuid);65 RTDECL(bool) RTUuidIsNull(PCRTUUID pUuid); 66 66 67 67 /** … … 75 75 76 76 /** 77 * Compares a UUID value with a UUID string. 78 * 79 * @returns 0 if eq, < 0 or > 0. 80 * @param pUuid1 First value to compare. 81 * @param pszString2 The 2nd UUID in string form. 82 */ 83 RTDECL(int) RTUuidCompareStr(PCRTUUID pUuid1, const char *pszString); 84 85 /** 77 86 * Converts binary UUID to its string representation. 78 87 * … … 82 91 * @param cchString pszString buffer length, must be >= RTUUID_STR_LENGTH. 83 92 */ 84 RTDECL(int) RTUuidToStr(PCRTUUID pUuid, char *pszString, unsignedcchString);93 RTDECL(int) RTUuidToStr(PCRTUUID pUuid, char *pszString, size_t cchString); 85 94 86 95 /** -
trunk/src/VBox/Runtime/generic/uuid-generic.cpp
r8245 r9738 44 44 45 45 46 /** 47 * Generates a new UUID value. 48 * 49 * @returns iprt status code. 50 * @param pUuid Where to store generated uuid. 51 */ 46 /** @todo move to a different file. */ 52 47 RTDECL(int) RTUuidCreate(PRTUUID pUuid) 53 48 { 54 49 /* validate input. */ 55 Assert Return(pUuid, VERR_INVALID_PARAMETER);50 AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER); 56 51 57 52 RTRandBytes(pUuid, sizeof(*pUuid)); … … 63 58 64 59 65 /**66 * Makes a null UUID value.67 *68 * @returns iprt status code.69 * @param pUuid Where to store generated null uuid.70 */71 60 RTDECL(int) RTUuidClear(PRTUUID pUuid) 72 61 { 73 Assert Return(pUuid, VERR_INVALID_PARAMETER);62 AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER); 74 63 pUuid->au64[0] = 0; 75 64 pUuid->au64[1] = 0; … … 78 67 79 68 80 /** 81 * Checks if UUID is null. 82 * 83 * @returns true if UUID is null. 84 * @param pUuid uuid to check. 85 */ 86 RTDECL(int) RTUuidIsNull(PCRTUUID pUuid) 87 { 88 AssertReturn(pUuid, VERR_INVALID_PARAMETER); 69 RTDECL(bool) RTUuidIsNull(PCRTUUID pUuid) 70 { 71 AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER); 89 72 return !pUuid->au64[0] 90 73 && !pUuid->au64[1]; … … 92 75 93 76 94 /**95 * Compares two UUID values.96 *97 * @returns 0 if eq, < 0 or > 0.98 * @param pUuid1 First value to compare.99 * @param pUuid2 Second value to compare.100 */101 77 RTDECL(int) RTUuidCompare(PCRTUUID pUuid1, PCRTUUID pUuid2) 102 78 { … … 104 80 * Special cases. 105 81 */ 82 /** @todo This differs in the windows implementation... check out which behavior we really want. */ 106 83 if (pUuid1 == pUuid2) 107 84 return 0; … … 110 87 if (!pUuid2) 111 88 return RTUuidIsNull(pUuid1) ? 0 : 1; 89 AssertPtr(pUuid1); 90 AssertPtr(pUuid2); 112 91 113 92 /* … … 138 117 139 118 140 /** 141 * Converts binary UUID to its string representation. 142 * 143 * @returns iprt status code. 144 * @param pUuid Uuid to convert. 145 * @param pszString Where to store result string. 146 * @param cchString pszString buffer length, must be >= RTUUID_STR_LENGTH. 147 */ 148 RTDECL(int) RTUuidToStr(PCRTUUID pUuid, char *pszString, unsigned cchString) 119 RTDECL(int) RTUuidCompareStr(PCRTUUID pUuid1, const char *pszString) 120 { 121 /* check params */ 122 AssertPtrReturn(pUuid1, -1); 123 AssertPtrReturn(pszString, 1); 124 125 /* 126 * Try convert the string to a UUID and then compare the two. 127 */ 128 RTUUID Uuid2; 129 int rc = RTUuidFromStr(&Uuid2, pszString); 130 AssertRCReturn(rc, 1); 131 132 return RTUuidCompare(pUuid1, &Uuid2); 133 } 134 135 136 RTDECL(int) RTUuidToStr(PCRTUUID pUuid, char *pszString, size_t cchString) 149 137 { 150 138 /* validate parameters */ 151 Assert Return(pUuid, VERR_INVALID_PARAMETER);152 Assert Return(pszString, VERR_INVALID_PARAMETER);139 AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER); 140 AssertPtrReturn(pszString, VERR_INVALID_PARAMETER); 153 141 AssertReturn(cchString >= RTUUID_STR_LENGTH, VERR_INVALID_PARAMETER); 154 142 … … 214 202 215 203 216 /**217 * Converts UUID from its string representation to binary format.218 *219 * @returns iprt status code.220 * @param pUuid Where to store result Uuid.221 * @param pszString String with UUID text data.222 */223 204 RTDECL(int) RTUuidFromStr(PRTUUID pUuid, const char *pszString) 224 205 { … … 247 228 * Validate parameters. 248 229 */ 249 Assert Return(pUuid, VERR_INVALID_PARAMETER);250 Assert Return(pszString, VERR_INVALID_PARAMETER);230 AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER); 231 AssertPtrReturn(pszString, VERR_INVALID_PARAMETER); 251 232 252 233 #define MY_CHECK(expr) do { if (RT_UNLIKELY(!(expr))) return VERR_INVALID_UUID_FORMAT; } while (0) -
trunk/src/VBox/Runtime/r3/win/uuid-win.cpp
r8245 r9738 42 42 43 43 44 /** 45 * Generates a new UUID value. 46 * 47 * @returns iprt status code. 48 * @param pUuid Where to store generated uuid. 49 */ 44 /** @todo split out this guy */ 50 45 RTDECL(int) RTUuidCreate(PRTUUID pUuid) 51 46 { 52 47 /* check params */ 53 if (pUuid == NULL) 54 { 55 AssertMsgFailed(("pUuid=NULL\n")); 56 return VERR_INVALID_PARAMETER; 57 } 48 AssertPtrReturn(pUuid, VERR_INVALID_POINTER); 58 49 59 50 RPC_STATUS rc = UuidCreate((UUID *)pUuid); 60 if ((rc == RPC_S_OK) || (rc == RPC_S_UUID_LOCAL_ONLY)) 51 if ( rc == RPC_S_OK 52 || rc == RPC_S_UUID_LOCAL_ONLY) 61 53 return VINF_SUCCESS; 62 54 … … 65 57 } 66 58 67 /** 68 * Makes null UUID value. 69 * 70 * @returns iprt status code. 71 * @param pUuid Where to store generated null uuid. 72 */ 59 73 60 RTDECL(int) RTUuidClear(PRTUUID pUuid) 74 61 { 75 62 /* check params */ 76 if (pUuid == NULL) 77 { 78 AssertMsgFailed(("pUuid=NULL\n")); 79 return VERR_INVALID_PARAMETER; 80 } 63 AssertPtrReturn(pUuid, VERR_INVALID_POINTER); 81 64 82 65 return RTErrConvertFromWin32(UuidCreateNil((UUID *)pUuid)); 83 66 } 84 67 85 /** 86 * Checks if UUID is null. 87 * 88 * @returns true if UUID is null. 89 * @param pUuid uuid to check. 90 */ 91 RTDECL(int) RTUuidIsNull(PCRTUUID pUuid) 68 69 RTDECL(bool) RTUuidIsNull(PCRTUUID pUuid) 92 70 { 93 71 /* check params */ 94 if (pUuid == NULL) 95 { 96 AssertMsgFailed(("pUuid=NULL\n")); 97 return TRUE; 98 } 72 AssertPtrReturn(pUuid, true); 99 73 100 74 RPC_STATUS status; 101 return UuidIsNil((UUID *)pUuid, &status);75 return !!UuidIsNil((UUID *)pUuid, &status); 102 76 } 103 77 104 /** 105 * Compares two UUID values. 106 * 107 * @returns 0 if eq, < 0 or > 0. 108 * @param pUuid1 First value to compare. 109 * @param pUuid2 Second value to compare. 110 */ 78 111 79 RTDECL(int) RTUuidCompare(PCRTUUID pUuid1, PCRTUUID pUuid2) 112 80 { 113 81 /* check params */ 114 if ((pUuid1 == NULL) || (pUuid2 == NULL)) 115 { 116 AssertMsgFailed(("Invalid parameters\n")); 117 return 1; 118 } 82 AssertPtrReturn(pUuid1, -1); 83 AssertPtrReturn(pUuid1, 1); 119 84 120 85 RPC_STATUS status; … … 122 87 } 123 88 124 /** 125 * Converts binary UUID to its string representation. 126 * 127 * @returns iprt status code. 128 * @param pUuid Uuid to convert. 129 * @param pszString Where to store result string. 130 * @param cchString pszString buffer length, must be >= RTUUID_STR_LENGTH. 131 */ 132 RTDECL(int) RTUuidToStr(PCRTUUID pUuid, char *pszString, unsigned cchString) 89 90 RTDECL(int) RTUuidCompareStr(PCRTUUID pUuid1, const char *pszString) 133 91 { 134 92 /* check params */ 135 if ((pUuid == NULL) || (pszString == NULL) || (cchString < RTUUID_STR_LENGTH)) 136 { 137 AssertMsgFailed(("Invalid parameters\n")); 138 return VERR_INVALID_PARAMETER; 139 } 93 AssertPtrReturn(pUuid1, -1); 94 AssertPtrReturn(pszString, 1); 140 95 141 RPC_STATUS rc; 142 char *pStr = NULL; 96 /* 97 * Try convert the string to a UUID and then compare the two. 98 */ 99 RTUUID Uuid2; 100 int rc = RTUuidFromStr(&Uuid2, pszString); 101 AssertRCReturn(rc, 1); 102 103 return RTUuidCompare(pUuid1, &Uuid2); 104 } 105 106 107 RTDECL(int) RTUuidToStr(PCRTUUID pUuid, char *pszString, size_t cchString) 108 { 109 /* check params */ 110 AssertPtrReturn(pUuid, VERR_INVALID_POINTER); 111 AssertPtrReturn(pszString, VERR_INVALID_POINTER); 112 AssertReturn(cchString >= RTUUID_STR_LENGTH, VERR_INVALID_PARAMETER); 113 114 /* 115 * Try convert it. 116 * 117 * The API allocates a new string buffer for us, so we can do our own 118 * buffer overflow handling. 119 */ 120 RPC_STATUS Status; 121 unsigned char *pszTmpStr = NULL; 143 122 #ifdef RPC_UNICODE_SUPPORTED 144 123 /* always use ASCII version! */ 145 rc = UuidToStringA((UUID *)pUuid, (unsigned char **)&pStr);124 Status = UuidToStringA((UUID *)pUuid, &pszTmpStr); 146 125 #else 147 rc = UuidToString((UUID *)pUuid, (unsigned char **)&pStr);126 Status = UuidToString((UUID *)pUuid, &pszTmpStr); 148 127 #endif 149 if ( rc!= RPC_S_OK)150 return RTErrConvertFromWin32( rc);128 if (Status != RPC_S_OK) 129 return RTErrConvertFromWin32(Status); 151 130 152 if (strlen(pStr) >= cchString) 153 { 154 /* out of buffer space */ 155 #ifdef RPC_UNICODE_SUPPORTED 156 /* always use ASCII version! */ 157 RpcStringFreeA((unsigned char **)&pStr); 158 #else 159 RpcStringFree((unsigned char **)&pStr); 160 #endif 161 AssertMsgFailed(("Buffer overflow\n")); 162 return ERROR_BUFFER_OVERFLOW; 163 } 164 165 /* copy str to user buffer */ 166 pszString[0] = '\0'; 167 strncat(pszString, pStr, cchString); 131 /* copy it. */ 132 int rc = VINF_SUCCESS; 133 size_t cch = strlen((char *)pszTmpStr); 134 if (cch < cchString) 135 memcpy(pszString, pszTmpStr, cchTmpStr + 1); 136 else 137 rc = ERROR_BUFFER_OVERFLOW; 168 138 169 139 /* free buffer */ 170 140 #ifdef RPC_UNICODE_SUPPORTED 171 141 /* always use ASCII version! */ 172 RpcStringFreeA( (unsigned char **)&pStr);142 RpcStringFreeA(&pszTmpStr); 173 143 #else 174 RpcStringFree( (unsigned char **)&pStr);144 RpcStringFree(&pszTmpStr); 175 145 #endif 176 146 177 147 /* all done */ 178 return VINF_SUCCESS;148 return rc; 179 149 } 180 150 181 /** 182 * Converts UUID from its string representation to binary format. 183 * 184 * @returns iprt status code. 185 * @param pUuid Where to store result Uuid. 186 * @param pszString String with UUID text data. 187 */ 151 188 152 RTDECL(int) RTUuidFromStr(PRTUUID pUuid, const char *pszString) 189 153 { 190 154 /* check params */ 191 if ((pUuid == NULL) || (pszString == NULL)) 192 { 193 AssertMsgFailed(("Invalid parameters\n")); 194 return VERR_INVALID_PARAMETER; 195 } 155 AssertPtrReturn(pUuid, VERR_INVALID_POINTER); 156 AssertPtrReturn(pszString, VERR_INVALID_POINTER); 196 157 197 158 RPC_STATUS rc; … … 206 167 } 207 168 169
Note:
See TracChangeset
for help on using the changeset viewer.