VirtualBox

Changeset 9741 in vbox for trunk/src/VBox/Runtime/r3


Ignore:
Timestamp:
Jun 16, 2008 10:46:46 PM (17 years ago)
Author:
vboxsync
Message:

Split out RTUuidCreate, so we don't drag in RTRand when we don't need to create UUIDs.

Location:
trunk/src/VBox/Runtime/r3/win
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/RTUuidCreate-win.cpp

    r9740 r9741  
    11/* $Id$ */
    22/** @file
    3  * IPRT UUID (unique identifiers) handling (win32 host).
     3 * IPRT - UUID, Windows RTUuidCreate implementation.
    44 */
    55
     
    3838#include <iprt/uuid.h>
    3939#include <iprt/assert.h>
    40 #include <iprt/string.h>
    4140#include <iprt/err.h>
    4241
     
    5756}
    5857
    59 
    60 RTDECL(int)  RTUuidClear(PRTUUID pUuid)
    61 {
    62     /* check params */
    63     AssertPtrReturn(pUuid, VERR_INVALID_POINTER);
    64 
    65     return RTErrConvertFromWin32(UuidCreateNil((UUID *)pUuid));
    66 }
    67 
    68 
    69 RTDECL(bool)  RTUuidIsNull(PCRTUUID pUuid)
    70 {
    71     /* check params */
    72     AssertPtrReturn(pUuid, true);
    73 
    74     RPC_STATUS status;
    75     return !!UuidIsNil((UUID *)pUuid, &status);
    76 }
    77 
    78 
    79 RTDECL(int)  RTUuidCompare(PCRTUUID pUuid1, PCRTUUID pUuid2)
    80 {
    81     /* check params */
    82     AssertPtrReturn(pUuid1, -1);
    83     AssertPtrReturn(pUuid1, 1);
    84 
    85     RPC_STATUS status;
    86     return UuidCompare((UUID *)pUuid1, (UUID *)pUuid2, &status);
    87 }
    88 
    89 
    90 RTDECL(int)  RTUuidCompareStr(PCRTUUID pUuid1, const char *pszString)
    91 {
    92     /* check params */
    93     AssertPtrReturn(pUuid1, -1);
    94     AssertPtrReturn(pszString, 1);
    95 
    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;
    122 #ifdef RPC_UNICODE_SUPPORTED
    123     /* always use ASCII version! */
    124     Status = UuidToStringA((UUID *)pUuid, &pszTmpStr);
    125 #else
    126     Status = UuidToString((UUID *)pUuid, &pszTmpStr);
    127 #endif
    128     if (Status != RPC_S_OK)
    129         return RTErrConvertFromWin32(Status);
    130 
    131     /* copy it. */
    132     int rc = VINF_SUCCESS;
    133     size_t cchTmpStr = strlen((char *)pszTmpStr);
    134     if (cchTmpStr < cchString)
    135         memcpy(pszString, pszTmpStr, cchTmpStr + 1);
    136     else
    137     {
    138         AssertFailed();
    139         rc = ERROR_BUFFER_OVERFLOW;
    140     }
    141 
    142     /* free buffer */
    143 #ifdef RPC_UNICODE_SUPPORTED
    144     /* always use ASCII version! */
    145     RpcStringFreeA(&pszTmpStr);
    146 #else
    147     RpcStringFree(&pszTmpStr);
    148 #endif
    149 
    150     /* all done */
    151     return rc;
    152 }
    153 
    154 
    155 RTDECL(int)  RTUuidFromStr(PRTUUID pUuid, const char *pszString)
    156 {
    157     /* check params */
    158     AssertPtrReturn(pUuid, VERR_INVALID_POINTER);
    159     AssertPtrReturn(pszString, VERR_INVALID_POINTER);
    160 
    161     RPC_STATUS rc;
    162 #ifdef RPC_UNICODE_SUPPORTED
    163     /* always use ASCII version! */
    164     rc = UuidFromStringA((unsigned char *)pszString, (UUID *)pUuid);
    165 #else
    166     rc = UuidFromString((unsigned char *)pszString, (UUID *)pUuid);
    167 #endif
    168 
    169     return RTErrConvertFromWin32(rc);
    170 }
    171 
    172 
  • trunk/src/VBox/Runtime/r3/win/uuid-win.cpp

    r9740 r9741  
    11/* $Id$ */
    22/** @file
    3  * IPRT UUID (unique identifiers) handling (win32 host).
     3 * IPRT - UUID, Windows implementation.
    44 */
    55
     
    4040#include <iprt/string.h>
    4141#include <iprt/err.h>
    42 
    43 
    44 /** @todo split out this guy */
    45 RTDECL(int)  RTUuidCreate(PRTUUID pUuid)
    46 {
    47     /* check params */
    48     AssertPtrReturn(pUuid, VERR_INVALID_POINTER);
    49 
    50     RPC_STATUS rc = UuidCreate((UUID *)pUuid);
    51     if (    rc == RPC_S_OK
    52         || rc == RPC_S_UUID_LOCAL_ONLY)
    53         return VINF_SUCCESS;
    54 
    55     /* error exit */
    56     return RTErrConvertFromWin32(rc);
    57 }
    5842
    5943
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette