strversion.cpp revision 4b783d68e6d569ab798901917ace422a4810edf0
/* $Id$ */
/** @file
* IPRT - Version String Parsing.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Defined Constants *
*******************************************************************************/
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
{
uint16_t l = 0;
{
break;
l++;
pszCur++;
}
/* Adjust block count to also count in the very first block */
if (*pszVer != '\0')
l++;
return l;
}
{
/* First make a copy of the version string so that we can modify it */
char *pszString;
if (RT_FAILURE(rc))
return rc;
/* Go to the beginning of the block we want to parse */
{
break;
if (*pszCur != '\0')
pszCur++;
}
{
/* Skip trailing non-digits at the start of the block */
{
break;
pszCur++;
}
/* Mark ending of the block */
*pszEnd = '\0';
/* Convert to number */
/* Skip trailing warnings */
if ( rc == VWRN_TRAILING_CHARS
|| rc == VWRN_TRAILING_SPACES)
rc = VINF_SUCCESS;
}
else
rc = VERR_NOT_FOUND;
return rc;
}
/**
* Compares two version strings and returns the result. The version string has
* to be made of at least one number section, each section delimited by a ".",
* e.g. "123.45.67". Trailing zeros at the beginning and non-digits in a section
* will be skipped, so "12.foo006" becomes "12.6".
*
* @returns iprt status code.
* Warnings are used to indicate convertion problems.
* @retval VWRN_NUMBER_TOO_BIG
* @retval VWRN_TRAILING_CHARS
* @retval VWRN_TRAILING_SPACES
* @retval VINF_SUCCESS
* @retval VERR_NO_MEMORY
* @retval VERR_NO_DIGITS
*
* @todo Deal with prefixes and suffixes!
* @param pszVer1 First version string to compare.
* @param pszVer2 First version string to compare.*
* @param pui8Res Pointer uint8_t value where to store the comparison result:
* 0 if equal, 1 if pszVer1 is greater, 2 if pszVer2 is greater.
*/
{
int rc = 0;
{
/* Figure out which version string is longer and set the corresponding
* pointers */
const char *pszShorter, *pszLonger;
{
}
{
}
/* Now process each section (delimited by a ".") */
*pui8Res = 0;
&& *pui8Res == 0
&& RT_SUCCESS(rc)
; i++)
{
if (RT_SUCCESS(rc))
{
{
/* If we're in the padding range, there are no numbers left
* to compare with anymore, so just assume "0" then */
val2 = 0;
}
else
{
}
}
if (RT_SUCCESS(rc))
{
{
break;
}
{
break;
}
}
}
}
else
{
rc = VERR_NO_DIGITS;
}
if (RT_FAILURE(rc))
*pui8Res = 0; /* Zero out value */
return rc;
}