VirtualBox

Ignore:
Timestamp:
Nov 13, 2009 4:30:14 PM (15 years ago)
Author:
vboxsync
Message:

VbglR3: Make use of RTStrVersionToUInt32().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp

    r24565 r24642  
    4040 * Requires strings in form of "majorVer.minorVer.build".
    4141 *
    42  * @returns 0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater.
     42 * @returns iprt status code.
    4343 *
    4444 * @param   pszVer1     First version string to compare.
    4545 * @param   pszVer2     First version string to compare.
    46  *
    47  * @todo Move this to IPRT and add support for more dots, suffixes and whatnot.
    48  */
    49 VBGLR3DECL(int) VbglR3HostVersionCompare(const char *pszVer1, const char *pszVer2)
    50 {
    51     /** @todo r=bird: not checking the return code, may be using uninitialized
    52      *        variables... I'll fix this when moving into the runtime.  */
    53     int iVer1Major, iVer1Minor, iVer1Build;
    54     sscanf(pszVer1, "%d.%d.%d", &iVer1Major, &iVer1Minor, &iVer1Build);
    55     int iVer2Major, iVer2Minor, iVer2Build;
    56     sscanf(pszVer2, "%d.%d.%d", &iVer2Major, &iVer2Minor, &iVer2Build);
    57 
    58     int iVer1Final = (iVer1Major * 10000) + (iVer1Minor * 100) + iVer1Build;
    59     int iVer2Final = (iVer2Major * 10000) + (iVer2Minor * 100) + iVer2Build;
    60 
    61     int rc = 0;
    62     if (iVer1Final > iVer2Final)
    63         rc = 1;
    64     else if (iVer2Final > iVer1Final)
    65         rc = 2;
     46 * @param   uint8_t     Pointer to comparison result:
     47 *                      0 if equal, 1 if Ver1 is greater, 2 if Ver2 is greater.
     48 *
     49 * @todo Move this to IPRT - where?
     50 */
     51VBGLR3DECL(int) VbglR3HostVersionCompare(const char *pszVer1, const char *pszVer2, uint8_t *puRes)
     52{
     53    uint32_t u32Ver1;
     54    uint32_t u32Ver2;
     55
     56    Assert(puRes);
     57    int rc = RTStrVersionToUInt32(pszVer1, &u32Ver1);
     58    if (RT_SUCCESS(rc))
     59        rc = RTStrVersionToUInt32(pszVer2, &u32Ver2);
     60
     61    *puRes = 0;
     62    if (RT_SUCCESS(rc))
     63    {
     64        if (u32Ver1 > u32Ver2)
     65            *puRes = 1;
     66        else if (u32Ver2 > u32Ver1)
     67            *puRes = 2;
     68    }
    6669    return rc;
    6770}
     
    166169    if (RT_SUCCESS(rc) && *pfUpdate)
    167170    {
    168         if (VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */
     171        uint8_t u8Res;
     172        rc = VbglR3HostVersionCompare(*ppszHostVersion, *ppszGuestVersion, &u8Res);
     173        if (RT_SUCCESS(rc) && u8Res == 1) /* Is host version greater than guest add version? */
    169174        {
    170175            /* Yay, we have an update! */
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