VirtualBox

Ignore:
Timestamp:
Sep 6, 2022 2:13:23 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
153486
Message:

IPRT/path: Added fFlags parameter to RTPathAppendEx and RTPathJoinEx to make it possible to select the path style. bugref:10286

Location:
trunk/src/VBox/Runtime/common/path
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/path/RTPathAppend.cpp

    r96407 r96609  
    4747RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend)
    4848{
    49     return RTPathAppendEx(pszPath, cbPathDst, pszAppend, RTSTR_MAX);
     49    return RTPathAppendEx(pszPath, cbPathDst, pszAppend, RTSTR_MAX, RTPATH_STR_F_STYLE_HOST);
    5050}
    5151
  • trunk/src/VBox/Runtime/common/path/RTPathAppendEx.cpp

    r96407 r96609  
    4646#include <iprt/errcore.h>
    4747#include <iprt/string.h>
     48
     49#define RTPATH_TEMPLATE_CPP_H "RTPathAppendEx.cpp.h"
     50#include "rtpath-expand-template.cpp.h"
    4851
    4952
     
    115118
    116119
    117 RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax)
     120RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax, uint32_t fFlags)
    118121{
    119122    char *pszPathEnd = RTStrEnd(pszPath, cbPathDst);
    120123    AssertReturn(pszPathEnd, VERR_INVALID_PARAMETER);
     124    Assert(RTPATH_STR_F_IS_VALID(fFlags, 0));
    121125
    122126    /*
     
    138142
    139143    /*
    140      * Balance slashes and check for buffer overflow.
     144     * Go to path style specific code now.
    141145     */
    142     if (!RTPATH_IS_SLASH(pszPathEnd[-1]))
     146    switch (fFlags & RTPATH_STR_F_STYLE_MASK)
    143147    {
    144         if (!RTPATH_IS_SLASH(pszAppend[0]))
    145         {
    146 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
    147             if (    (size_t)(pszPathEnd - pszPath) == 2
    148                 &&  pszPath[1] == ':'
    149                 &&  RT_C_IS_ALPHA(pszPath[0]))
    150             {
    151                 if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
    152                     return VERR_BUFFER_OVERFLOW;
    153             }
    154             else
     148#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     149        case RTPATH_STR_F_STYLE_HOST:
    155150#endif
    156             {
    157                 if ((size_t)(pszPathEnd - pszPath) + 1 + cchAppend >= cbPathDst)
    158                     return VERR_BUFFER_OVERFLOW;
    159                 *pszPathEnd++ = RTPATH_SLASH;
    160             }
    161         }
    162         else
    163         {
    164             /* One slash is sufficient at this point. */
    165             while (cchAppend > 1 && RTPATH_IS_SLASH(pszAppend[1]))
    166                 pszAppend++, cchAppend--;
     151        case RTPATH_STR_F_STYLE_DOS:
     152            return rtPathAppendExStyleDos(pszPath, cbPathDst, pszPathEnd, pszAppend, cchAppend);
    167153
    168             if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
    169                 return VERR_BUFFER_OVERFLOW;
    170         }
     154#if RTPATH_STYLE != RTPATH_STR_F_STYLE_DOS
     155        case RTPATH_STR_F_STYLE_HOST:
     156#endif
     157        case RTPATH_STR_F_STYLE_UNIX:
     158            return rtPathAppendExStyleUnix(pszPath, cbPathDst, pszPathEnd, pszAppend, cchAppend);
     159
     160        default:
     161            AssertFailedReturn(VERR_INVALID_FLAGS); /* impossible */
    171162    }
    172     else
    173     {
    174         /* No slashes needed in the appended bit. */
    175         while (cchAppend && RTPATH_IS_SLASH(*pszAppend))
    176             pszAppend++, cchAppend--;
    177 
    178         /* In the leading path we can skip unnecessary trailing slashes, but
    179            be sure to leave one. */
    180         size_t const cchRoot = rtPathRootSpecLen2(pszPath);
    181         while (     (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot)
    182                &&   RTPATH_IS_SLASH(pszPathEnd[-2]))
    183             pszPathEnd--;
    184 
    185         if ((size_t)(pszPathEnd - pszPath) + cchAppend >= cbPathDst)
    186             return VERR_BUFFER_OVERFLOW;
    187     }
    188 
    189     /*
    190      * What remains now is the just the copying.
    191      */
    192     memcpy(pszPathEnd, pszAppend, cchAppend);
    193     pszPathEnd[cchAppend] = '\0';
    194     return VINF_SUCCESS;
    195163}
    196164
  • trunk/src/VBox/Runtime/common/path/RTPathAppendEx.cpp.h

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/VBox-3.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp58652,​70973
      /branches/VBox-3.2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp66309,​66318
      /branches/VBox-4.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp70873
      /branches/VBox-4.1/src/VBox/Runtime/common/path/RTPathAppendEx.cpp74233,​78414,​78691,​81841,​82127,​85941,​85944-85947,​85949-85950,​85953,​86701,​86728,​87009
      /branches/VBox-4.2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp86229-86230,​86234,​86529,​91503-91504,​91506-91508,​91510,​91514-91515,​91521,​108112,​108114,​108127
      /branches/VBox-4.3/src/VBox/Runtime/common/path/RTPathAppendEx.cpp89714,​91223,​93628-93629,​94066,​94839,​94897,​95154,​95164,​95167,​95295,​95338,​95353-95354,​95356,​95367,​95451,​95475,​95477,​95480,​95507,​95640,​95659,​95661,​95663,​98913-98914
      /branches/VBox-4.3/trunk/src/VBox/Runtime/common/path/RTPathAppendEx.cpp91223
      /branches/VBox-5.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp104938,​104943,​104950,​104987-104988,​104990,​106453
      /branches/VBox-5.1/src/VBox/Runtime/common/path/RTPathAppendEx.cpp112367,​116543,​116550,​116568,​116573
      /branches/VBox-5.2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp119536,​120083,​120099,​120213,​120221,​120239,​123597-123598,​123600-123601,​123755,​124263,​124273,​124277-124279,​124284-124286,​124288-124290,​125768,​125779-125780,​125812,​127158-127159,​127162-127167,​127180
      /branches/VBox-6.0/src/VBox/Runtime/common/path/RTPathAppendEx.cpp130474-130475,​130477,​130479,​131352
      /branches/VBox-6.1/src/VBox/Runtime/common/path/RTPathAppendEx.cpp141521,​141567-141568,​141588-141590,​141592-141595,​141652,​141920
      /branches/aeichner/vbox-chromium-cleanup/src/VBox/Runtime/common/path/RTPathAppendEx.cpp129818-129851,​129853-129861,​129871-129872,​129876,​129880,​129882,​130013-130015,​130094-130095
      /branches/andy/draganddrop/src/VBox/Runtime/common/path/RTPathAppendEx.cpp90781-91268
      /branches/andy/guestctrl20/src/VBox/Runtime/common/path/RTPathAppendEx.cpp78916,​78930
      /branches/andy/pdmaudio/src/VBox/Runtime/common/path/RTPathAppendEx.cpp94582,​94641,​94654,​94688,​94778,​94783,​94816,​95197,​95215-95216,​95250,​95279,​95505-95506,​95543,​95694,​96323,​96470-96471,​96582,​96587,​96802-96803,​96817,​96904,​96967,​96999,​97020-97021,​97025,​97050,​97099
      /branches/bird/hardenedwindows/src/VBox/Runtime/common/path/RTPathAppendEx.cpp92692-94610
      /branches/dsen/gui/src/VBox/Runtime/common/path/RTPathAppendEx.cpp79076-79078,​79089,​79109-79110,​79112-79113,​79127-79130,​79134,​79141,​79151,​79155,​79157-79159,​79193,​79197
      /branches/dsen/gui2/src/VBox/Runtime/common/path/RTPathAppendEx.cpp79224,​79228,​79233,​79235,​79258,​79262-79263,​79273,​79341,​79345,​79354,​79357,​79387-79388,​79559-79569,​79572-79573,​79578,​79581-79582,​79590-79591,​79598-79599,​79602-79603,​79605-79606,​79632,​79635,​79637,​79644
      /branches/dsen/gui3/src/VBox/Runtime/common/path/RTPathAppendEx.cpp79645-79692
    r96608 r96609  
    11/* $Id$ */
    22/** @file
    3  * IPRT - RTPathAppendEx
     3 * IPRT - rtPathAppendEx - Code Template.
    44 */
    55
     
    3636
    3737
    38 /*********************************************************************************************************************************
    39 *   Header Files                                                                                                                 *
    40 *********************************************************************************************************************************/
    41 #include "internal/iprt.h"
    42 #include <iprt/path.h>
    43 
    44 #include <iprt/assert.h>
    45 #include <iprt/ctype.h>
    46 #include <iprt/errcore.h>
    47 #include <iprt/string.h>
    48 
    49 
    5038/**
    5139 * Figures the length of the root part of the path.
     
    6048 *          counts them.)
    6149 */
    62 static size_t rtPathRootSpecLen2(const char *pszPath)
     50DECLINLINE(size_t) RTPATH_STYLE_FN(rtPathRootSpecLen2)(const char *pszPath)
    6351{
    6452    /* fend of wildlife. */
     
    6957    if (RTPATH_IS_SLASH(pszPath[0]))
    7058    {
    71 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
     59#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
    7260        /* UNC? */
    7361        if (    RTPATH_IS_SLASH(pszPath[1])
     
    10088    }
    10189
    102 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
     90#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
    10391    /* Drive specifier? */
    10492    if (   pszPath[0] != '\0'
     
    115103
    116104
    117 RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax)
     105/** Internal worker for RTPathAppendEx. */
     106DECLINLINE(int) RTPATH_STYLE_FN(rtPathAppendEx)(char *pszPath, size_t cbPathDst, char *pszPathEnd,
     107                                                const char *pszAppend, size_t cchAppend)
    118108{
    119     char *pszPathEnd = RTStrEnd(pszPath, cbPathDst);
    120     AssertReturn(pszPathEnd, VERR_INVALID_PARAMETER);
    121 
    122     /*
    123      * Special cases.
    124      */
    125     if (!pszAppend)
    126         return VINF_SUCCESS;
    127     size_t cchAppend = RTStrNLen(pszAppend, cchAppendMax);
    128     if (!cchAppend)
    129         return VINF_SUCCESS;
    130     if (pszPathEnd == pszPath)
    131     {
    132         if (cchAppend >= cbPathDst)
    133             return VERR_BUFFER_OVERFLOW;
    134         memcpy(pszPath, pszAppend, cchAppend);
    135         pszPath[cchAppend] = '\0';
    136         return VINF_SUCCESS;
    137     }
    138 
    139109    /*
    140110     * Balance slashes and check for buffer overflow.
     
    144114        if (!RTPATH_IS_SLASH(pszAppend[0]))
    145115        {
    146 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
     116#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
    147117            if (    (size_t)(pszPathEnd - pszPath) == 2
    148118                &&  pszPath[1] == ':'
     
    178148        /* In the leading path we can skip unnecessary trailing slashes, but
    179149           be sure to leave one. */
    180         size_t const cchRoot = rtPathRootSpecLen2(pszPath);
     150        size_t const cchRoot = RTPATH_STYLE_FN(rtPathRootSpecLen2)(pszPath);
    181151        while (     (size_t)(pszPathEnd - pszPath) > RT_MAX(1, cchRoot)
    182152               &&   RTPATH_IS_SLASH(pszPathEnd[-2]))
  • trunk/src/VBox/Runtime/common/path/RTPathJoinEx.cpp

    r96407 r96609  
    5050RTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst,
    5151                         const char *pszPathSrc, size_t cchPathSrcMax,
    52                          const char *pszAppend, size_t cchAppendMax)
     52                         const char *pszAppend, size_t cchAppendMax, uint32_t fFlags)
    5353{
    5454    AssertPtr(pszPathDst);
    5555    AssertPtr(pszPathSrc);
    5656    AssertPtr(pszAppend);
     57    Assert(RTPATH_STR_F_IS_VALID(fFlags, 0));
    5758
    5859    /*
     
    6566    pszPathDst[cchPathSrc] = '\0';
    6667
    67     return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax);
     68    return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax, fFlags);
    6869}
    6970
Note: See TracChangeset for help on using the changeset viewer.

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