VirtualBox

Changeset 9741 in vbox


Ignore:
Timestamp:
Jun 16, 2008 10:46:46 PM (16 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
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r9723 r9741  
    287287        r3/win/utf8-win.cpp \
    288288        r3/win/uuid-win.cpp \
     289        r3/win/RTUuidCreate-win.cpp \
    289290        win/errmsgwin.cpp \
    290291        win/RTErrConvertFromWin32.cpp
     
    301302        generic/RTTimeLocalNow-generic.cpp \
    302303        generic/RTTimerCreate-generic.cpp \
     304        generic/RTUuidCreate-generic.cpp \
    303305        generic/utf16locale-generic.cpp \
    304306        generic/uuid-generic.cpp \
     
    348350        generic/RTTimeLocalNow-generic.cpp \
    349351        generic/RTTimerCreate-generic.cpp \
     352        generic/RTUuidCreate-generic.cpp \
    350353        generic/semnoint-generic.cpp \
    351354        generic/semsrw-generic.cpp \
     
    385388        generic/RTTimeLocalNow-generic.cpp \
    386389        generic/RTTimerCreate-generic.cpp \
     390        generic/RTUuidCreate-generic.cpp \
    387391        generic/sched-generic.cpp \
    388392        generic/timer-generic.cpp \
     
    420424        generic/RTTimeLocalNow-generic.cpp \
    421425        generic/RTTimerCreate-generic.cpp \
     426        generic/RTUuidCreate-generic.cpp \
    422427        generic/sched-generic.cpp \
    423428        generic/utf16locale-generic.cpp \
     
    455460        generic/RTTimeLocalNow-generic.cpp \
    456461        generic/RTTimerCreate-generic.cpp \
     462        generic/RTUuidCreate-generic.cpp \
    457463        generic/sched-generic.cpp \
    458464        generic/utf16locale-generic.cpp \
     
    505511        generic/RTLogWriteDebugger-generic.cpp \
    506512        generic/RTTimeLocalNow-generic.cpp \
     513        generic/RTUuidCreate-generic.cpp \
    507514        generic/sched-generic.cpp \
    508515        generic/semnoint-generic.cpp \
  • trunk/src/VBox/Runtime/generic/RTUuidCreate-generic.cpp

    r9738 r9741  
    11/* $Id$ */
    22/** @file
    3  * IPRT - UUID, Generic.
     3 * IPRT - UUID, Generic RTUuidCreate implementation.
    44 */
    55
     
    3636#include <iprt/assert.h>
    3737#include <iprt/err.h>
    38 #include <iprt/time.h>
    39 #include <iprt/asm.h>
    4038#include <iprt/rand.h>
    4139
    4240
    43 /* WARNING: This implementation ASSUMES little endian. */
     41/* WARNING: This implementation ASSUMES little endian. Needs testing on big endian! */
    4442
    4543
     
    5755}
    5856
    59 
    60 RTDECL(int)  RTUuidClear(PRTUUID pUuid)
    61 {
    62     AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
    63     pUuid->au64[0] = 0;
    64     pUuid->au64[1] = 0;
    65     return VINF_SUCCESS;
    66 }
    67 
    68 
    69 RTDECL(bool)  RTUuidIsNull(PCRTUUID pUuid)
    70 {
    71     AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
    72     return !pUuid->au64[0]
    73         && !pUuid->au64[1];
    74 }
    75 
    76 
    77 RTDECL(int)  RTUuidCompare(PCRTUUID pUuid1, PCRTUUID pUuid2)
    78 {
    79     /*
    80      * Special cases.
    81      */
    82     /** @todo This differs in the windows implementation... check out which behavior we really want. */
    83     if (pUuid1 == pUuid2)
    84         return 0;
    85     if (!pUuid1)
    86         return RTUuidIsNull(pUuid2) ? 0 : -1;
    87     if (!pUuid2)
    88         return RTUuidIsNull(pUuid1) ? 0 : 1;
    89     AssertPtr(pUuid1);
    90     AssertPtr(pUuid2);
    91 
    92     /*
    93      * Standard cases.
    94      */
    95     if (pUuid1->Gen.u32TimeLow != pUuid2->Gen.u32TimeLow)
    96         return pUuid1->Gen.u32TimeLow < pUuid2->Gen.u32TimeLow ? -1 : 1;
    97     if (pUuid1->Gen.u16TimeMid != pUuid2->Gen.u16TimeMid)
    98         return pUuid1->Gen.u16TimeMid < pUuid2->Gen.u16TimeMid ? -1 : 1;
    99     if (pUuid1->Gen.u16TimeHiAndVersion != pUuid2->Gen.u16TimeHiAndVersion)
    100         return pUuid1->Gen.u16TimeHiAndVersion < pUuid2->Gen.u16TimeHiAndVersion ? -1 : 1;
    101     if (pUuid1->Gen.u16ClockSeq != pUuid2->Gen.u16ClockSeq)
    102         return pUuid1->Gen.u16ClockSeq < pUuid2->Gen.u16ClockSeq ? -1 : 1;
    103     if (pUuid1->Gen.au8Node[0] != pUuid2->Gen.au8Node[0])
    104         return pUuid1->Gen.au8Node[0] < pUuid2->Gen.au8Node[0] ? -1 : 1;
    105     if (pUuid1->Gen.au8Node[1] != pUuid2->Gen.au8Node[1])
    106         return pUuid1->Gen.au8Node[1] < pUuid2->Gen.au8Node[1] ? -1 : 1;
    107     if (pUuid1->Gen.au8Node[2] != pUuid2->Gen.au8Node[2])
    108         return pUuid1->Gen.au8Node[2] < pUuid2->Gen.au8Node[2] ? -1 : 1;
    109     if (pUuid1->Gen.au8Node[3] != pUuid2->Gen.au8Node[3])
    110         return pUuid1->Gen.au8Node[3] < pUuid2->Gen.au8Node[3] ? -1 : 1;
    111     if (pUuid1->Gen.au8Node[4] != pUuid2->Gen.au8Node[4])
    112         return pUuid1->Gen.au8Node[4] < pUuid2->Gen.au8Node[4] ? -1 : 1;
    113     if (pUuid1->Gen.au8Node[5] != pUuid2->Gen.au8Node[5])
    114         return pUuid1->Gen.au8Node[5] < pUuid2->Gen.au8Node[5] ? -1 : 1;
    115     return 0;
    116 }
    117 
    118 
    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)
    137 {
    138     /* validate parameters */
    139     AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
    140     AssertPtrReturn(pszString, VERR_INVALID_PARAMETER);
    141     AssertReturn(cchString >= RTUUID_STR_LENGTH, VERR_INVALID_PARAMETER);
    142 
    143     /*
    144      * RTStrPrintf(,,"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
    145      *             pUuid->Gen.u32TimeLow,
    146      *             pUuid->Gen.u16TimeMin,
    147      *             pUuid->Gen.u16TimeHiAndVersion,
    148      *             pUuid->Gen.u16ClockSeq & 0xff,
    149      *             pUuid->Gen.u16ClockSeq >> 8,
    150      *             pUuid->Gen.au8Node[0],
    151      *             pUuid->Gen.au8Node[1],
    152      *             pUuid->Gen.au8Node[2],
    153      *             pUuid->Gen.au8Node[3],
    154      *             pUuid->Gen.au8Node[4],
    155      *             pUuid->Gen.au8Node[5]);
    156      */
    157     static const char s_achDigits[17] = "0123456789abcdef";
    158     uint32_t u32TimeLow = pUuid->Gen.u32TimeLow;
    159     pszString[ 0] = s_achDigits[(u32TimeLow >> 28)/*& 0xf*/];
    160     pszString[ 1] = s_achDigits[(u32TimeLow >> 24) & 0xf];
    161     pszString[ 2] = s_achDigits[(u32TimeLow >> 20) & 0xf];
    162     pszString[ 3] = s_achDigits[(u32TimeLow >> 16) & 0xf];
    163     pszString[ 4] = s_achDigits[(u32TimeLow >> 12) & 0xf];
    164     pszString[ 5] = s_achDigits[(u32TimeLow >>  8) & 0xf];
    165     pszString[ 6] = s_achDigits[(u32TimeLow >>  4) & 0xf];
    166     pszString[ 7] = s_achDigits[(u32TimeLow/*>>0*/)& 0xf];
    167     pszString[ 8] = '-';
    168     unsigned u = pUuid->Gen.u16TimeMid;
    169     pszString[ 9] = s_achDigits[(u >> 12)/*& 0xf*/];
    170     pszString[10] = s_achDigits[(u >>  8) & 0xf];
    171     pszString[11] = s_achDigits[(u >>  4) & 0xf];
    172     pszString[12] = s_achDigits[(u/*>>0*/)& 0xf];
    173     pszString[13] = '-';
    174     u = pUuid->Gen.u16TimeHiAndVersion;
    175     pszString[14] = s_achDigits[(u >> 12)/*& 0xf*/];
    176     pszString[15] = s_achDigits[(u >>  8) & 0xf];
    177     pszString[16] = s_achDigits[(u >>  4) & 0xf];
    178     pszString[17] = s_achDigits[(u/*>>0*/)& 0xf];
    179     pszString[18] = '-';
    180     u = pUuid->Gen.u16ClockSeq;
    181     pszString[19] = s_achDigits[(u >>  4) & 0xf];
    182     pszString[20] = s_achDigits[(u/*>>0*/)& 0xf];
    183     pszString[21] = s_achDigits[(u >> 12)/*& 0xf*/];
    184     pszString[22] = s_achDigits[(u >>  8) & 0xf];
    185     pszString[23] = '-';
    186     pszString[24] = s_achDigits[pUuid->Gen.au8Node[0] >> 4];
    187     pszString[25] = s_achDigits[pUuid->Gen.au8Node[0] & 0xf];
    188     pszString[26] = s_achDigits[pUuid->Gen.au8Node[1] >> 4];
    189     pszString[27] = s_achDigits[pUuid->Gen.au8Node[1] & 0xf];
    190     pszString[28] = s_achDigits[pUuid->Gen.au8Node[2] >> 4];
    191     pszString[29] = s_achDigits[pUuid->Gen.au8Node[2] & 0xf];
    192     pszString[30] = s_achDigits[pUuid->Gen.au8Node[3] >> 4];
    193     pszString[31] = s_achDigits[pUuid->Gen.au8Node[3] & 0xf];
    194     pszString[32] = s_achDigits[pUuid->Gen.au8Node[4] >> 4];
    195     pszString[33] = s_achDigits[pUuid->Gen.au8Node[4] & 0xf];
    196     pszString[34] = s_achDigits[pUuid->Gen.au8Node[5] >> 4];
    197     pszString[35] = s_achDigits[pUuid->Gen.au8Node[5] & 0xf];
    198     pszString[36] = '\0';
    199 
    200     return VINF_SUCCESS;
    201 }
    202 
    203 
    204 RTDECL(int)  RTUuidFromStr(PRTUUID pUuid, const char *pszString)
    205 {
    206     /* 0xff if not a hex number, otherwise the value. (Assumes UTF-8 encoded strings.) */
    207     static const uint8_t s_aDigits[256] =
    208     {
    209         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 0..0f */
    210         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 10..1f */
    211         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 20..2f */
    212         0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07,  0x08,0x09,0xff,0xff, 0xff,0xff,0xff,0xff, /* 30..3f */
    213         0xff,0x0a,0x0b,0x0c, 0x0d,0x0e,0x0f,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 40..4f */
    214         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 50..5f */
    215         0xff,0x0a,0x0b,0x0c, 0x0d,0x0e,0x0f,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 60..6f */
    216         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 70..7f */
    217         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 80..8f */
    218         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 90..9f */
    219         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* a0..af */
    220         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* b0..bf */
    221         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* c0..cf */
    222         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* d0..df */
    223         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* e0..ef */
    224         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* f0..ff */
    225     };
    226 
    227     /*
    228      * Validate parameters.
    229      */
    230     AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
    231     AssertPtrReturn(pszString, VERR_INVALID_PARAMETER);
    232 
    233 #define MY_CHECK(expr) do { if (RT_UNLIKELY(!(expr))) return VERR_INVALID_UUID_FORMAT; } while (0)
    234 #define MY_ISXDIGIT(ch) (s_aDigits[(ch) & 0xff] != 0xff)
    235     MY_CHECK(MY_ISXDIGIT(pszString[ 0]));
    236     MY_CHECK(MY_ISXDIGIT(pszString[ 1]));
    237     MY_CHECK(MY_ISXDIGIT(pszString[ 2]));
    238     MY_CHECK(MY_ISXDIGIT(pszString[ 3]));
    239     MY_CHECK(MY_ISXDIGIT(pszString[ 4]));
    240     MY_CHECK(MY_ISXDIGIT(pszString[ 5]));
    241     MY_CHECK(MY_ISXDIGIT(pszString[ 6]));
    242     MY_CHECK(MY_ISXDIGIT(pszString[ 7]));
    243     MY_CHECK(pszString[ 8] == '-');
    244     MY_CHECK(MY_ISXDIGIT(pszString[ 9]));
    245     MY_CHECK(MY_ISXDIGIT(pszString[10]));
    246     MY_CHECK(MY_ISXDIGIT(pszString[11]));
    247     MY_CHECK(MY_ISXDIGIT(pszString[12]));
    248     MY_CHECK(pszString[13] == '-');
    249     MY_CHECK(MY_ISXDIGIT(pszString[14]));
    250     MY_CHECK(MY_ISXDIGIT(pszString[15]));
    251     MY_CHECK(MY_ISXDIGIT(pszString[16]));
    252     MY_CHECK(MY_ISXDIGIT(pszString[17]));
    253     MY_CHECK(pszString[18] == '-');
    254     MY_CHECK(MY_ISXDIGIT(pszString[19]));
    255     MY_CHECK(MY_ISXDIGIT(pszString[20]));
    256     MY_CHECK(MY_ISXDIGIT(pszString[21]));
    257     MY_CHECK(MY_ISXDIGIT(pszString[22]));
    258     MY_CHECK(pszString[23] == '-');
    259     MY_CHECK(MY_ISXDIGIT(pszString[24]));
    260     MY_CHECK(MY_ISXDIGIT(pszString[25]));
    261     MY_CHECK(MY_ISXDIGIT(pszString[26]));
    262     MY_CHECK(MY_ISXDIGIT(pszString[27]));
    263     MY_CHECK(MY_ISXDIGIT(pszString[28]));
    264     MY_CHECK(MY_ISXDIGIT(pszString[29]));
    265     MY_CHECK(MY_ISXDIGIT(pszString[30]));
    266     MY_CHECK(MY_ISXDIGIT(pszString[31]));
    267     MY_CHECK(MY_ISXDIGIT(pszString[32]));
    268     MY_CHECK(MY_ISXDIGIT(pszString[33]));
    269     MY_CHECK(MY_ISXDIGIT(pszString[34]));
    270     MY_CHECK(MY_ISXDIGIT(pszString[35]));
    271     MY_CHECK(!pszString[36]);
    272 #undef MY_ISXDIGIT
    273 #undef MY_CHECK
    274 
    275     /*
    276      * Inverse of RTUuidToStr (see above).
    277      */
    278 #define MY_TONUM(ch) (s_aDigits[(ch) & 0xff])
    279     pUuid->Gen.u32TimeLow = (uint32_t)MY_TONUM(pszString[ 0]) << 28
    280                           | (uint32_t)MY_TONUM(pszString[ 1]) << 24
    281                           | (uint32_t)MY_TONUM(pszString[ 2]) << 20
    282                           | (uint32_t)MY_TONUM(pszString[ 3]) << 16
    283                           | (uint32_t)MY_TONUM(pszString[ 4]) << 12
    284                           | (uint32_t)MY_TONUM(pszString[ 5]) <<  8
    285                           | (uint32_t)MY_TONUM(pszString[ 6]) <<  4
    286                           | (uint32_t)MY_TONUM(pszString[ 7]);
    287     pUuid->Gen.u16TimeMid = (uint16_t)MY_TONUM(pszString[ 9]) << 12
    288                           | (uint16_t)MY_TONUM(pszString[10]) << 8
    289                           | (uint16_t)MY_TONUM(pszString[11]) << 4
    290                           | (uint16_t)MY_TONUM(pszString[12]);
    291     pUuid->Gen.u16TimeHiAndVersion =
    292                             (uint16_t)MY_TONUM(pszString[14]) << 12
    293                           | (uint16_t)MY_TONUM(pszString[15]) << 8
    294                           | (uint16_t)MY_TONUM(pszString[16]) << 4
    295                           | (uint16_t)MY_TONUM(pszString[17]);
    296     pUuid->Gen.u16ClockSeq =(uint16_t)MY_TONUM(pszString[19]) << 4
    297                           | (uint16_t)MY_TONUM(pszString[20])
    298                           | (uint16_t)MY_TONUM(pszString[21]) << 12
    299                           | (uint16_t)MY_TONUM(pszString[22]) << 8;
    300     pUuid->Gen.au8Node[0] = (uint8_t)MY_TONUM(pszString[24]) << 4
    301                           | (uint8_t)MY_TONUM(pszString[25]);
    302     pUuid->Gen.au8Node[1] = (uint8_t)MY_TONUM(pszString[26]) << 4
    303                           | (uint8_t)MY_TONUM(pszString[27]);
    304     pUuid->Gen.au8Node[2] = (uint8_t)MY_TONUM(pszString[28]) << 4
    305                           | (uint8_t)MY_TONUM(pszString[29]);
    306     pUuid->Gen.au8Node[3] = (uint8_t)MY_TONUM(pszString[30]) << 4
    307                           | (uint8_t)MY_TONUM(pszString[31]);
    308     pUuid->Gen.au8Node[4] = (uint8_t)MY_TONUM(pszString[32]) << 4
    309                           | (uint8_t)MY_TONUM(pszString[33]);
    310     pUuid->Gen.au8Node[5] = (uint8_t)MY_TONUM(pszString[34]) << 4
    311                           | (uint8_t)MY_TONUM(pszString[35]);
    312 #undef MY_TONUM
    313     return VINF_SUCCESS;
    314 }
    315 
  • trunk/src/VBox/Runtime/generic/uuid-generic.cpp

    r9738 r9741  
    3636#include <iprt/assert.h>
    3737#include <iprt/err.h>
    38 #include <iprt/time.h>
    39 #include <iprt/asm.h>
    40 #include <iprt/rand.h>
    41 
    42 
    43 /* WARNING: This implementation ASSUMES little endian. */
    44 
    45 
    46 /** @todo move to a different file. */
    47 RTDECL(int)  RTUuidCreate(PRTUUID pUuid)
    48 {
    49     /* validate input. */
    50     AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
    51 
    52     RTRandBytes(pUuid, sizeof(*pUuid));
    53     pUuid->Gen.u16ClockSeq = (pUuid->Gen.u16ClockSeq & 0x3fff) | 0x8000;
    54     pUuid->Gen.u16TimeHiAndVersion = (pUuid->Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
    55 
    56     return VINF_SUCCESS;
    57 }
     38
     39
     40/* WARNING: This implementation ASSUMES little endian. Needs testing on big endian! */
    5841
    5942
  • 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