strversion.cpp revision 4b783d68e6d569ab798901917ace422a4810edf0
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * IPRT - Version String Parsing.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * available from http://www.virtualbox.org. This file is free software;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * The contents of this file may alternatively be used under the terms
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * of the Common Development and Distribution License Version 1.0
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * VirtualBox OSE distribution, in which case the provisions of the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * CDDL are applicable instead of those of the GPL.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * You may elect to license modified versions of this file under the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * terms and conditions of either the GPL or the CDDL or both.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * additional information or have any questions.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync/*******************************************************************************
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync* Header Files *
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync*******************************************************************************/
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/*******************************************************************************
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync* Defined Constants *
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync*******************************************************************************/
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/*******************************************************************************
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync* Internal Functions *
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync*******************************************************************************/
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsyncstatic uint16_t RTStrVersionGetBlockCount(const char *pszVer)
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Adjust block count to also count in the very first block */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsyncstatic int RTStrVersionGetUInt32(const char *pszVer, uint16_t u16Block, uint32_t *pu32)
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* First make a copy of the version string so that we can modify it */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Go to the beginning of the block we want to parse */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Skip trailing non-digits at the start of the block */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Mark ending of the block */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Convert to number */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync rc = RTStrToUInt32Ex(pszCur, NULL /* ppszNext */, 10 /* Base */, pu32);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync /* Skip trailing warnings */
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Compares two version strings and returns the result. The version string has
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * to be made of at least one number section, each section delimited by a ".",
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * e.g. "123.45.67". Trailing zeros at the beginning and non-digits in a section
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * will be skipped, so "12.foo006" becomes "12.6".
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @returns iprt status code.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * Warnings are used to indicate convertion problems.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @retval VWRN_NUMBER_TOO_BIG
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @retval VWRN_TRAILING_CHARS
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @retval VWRN_TRAILING_SPACES
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @retval VINF_SUCCESS
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @retval VERR_NO_MEMORY
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @retval VERR_NO_DIGITS
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @todo Deal with prefixes and suffixes!
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @param pszVer1 First version string to compare.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @param pszVer2 First version string to compare.*
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * @param pui8Res Pointer uint8_t value where to store the comparison result:
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync * 0 if equal, 1 if pszVer1 is greater, 2 if pszVer2 is greater.
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsyncint RTStrVersionCompare(const char *pszVer1, const char *pszVer2, uint8_t *pui8Res)
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync uint16_t len1 = RTStrVersionGetBlockCount(pszVer1);
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync uint16_t len2 = RTStrVersionGetBlockCount(pszVer2);
int rc = 0;
*pui8Res = 0;
&& *pui8Res == 0
val2 = 0;
return rc;