Changeset 9738 in vbox for trunk/src/VBox/Runtime/r3/win
- Timestamp:
- Jun 16, 2008 10:38:49 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.