VirtualBox

Changeset 78100 in vbox


Ignore:
Timestamp:
Apr 10, 2019 4:52:24 PM (5 years ago)
Author:
vboxsync
Message:

iprt/cpp/path.h: Added RTPathAbsExCxx wrappers and made the existing RTPathAbCxx ones use RTPathAbsEx and handle stuff larger than RTPATH_MAX. Untested. bugref:9172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/path.h

    r76585 r78100  
    4545 *
    4646 * @returns IPRT status code.
    47  * @param   rStrAbs         Reference to the destiation string.
     47 * @param   rStrAbs         Reference to the destination string.
    4848 * @param   pszRelative     The relative source string.
    4949 */
     
    5454    if (RT_SUCCESS(rc))
    5555    {
    56         char *pszDst = rStrAbs.mutableRaw();
    57         rc = RTPathAbs(pszRelative, pszDst, rStrAbs.capacity());
    58         if (RT_FAILURE(rc))
     56        unsigned cTries = 8;
     57        for (;;)
     58        {
     59            char *pszDst = rStrAbs.mutableRaw();
     60            size_t cbCap = rStrAbs.capacity();
     61            rc = RTPathAbsEx(NULL, pszRelative, RTPATH_STR_F_STYLE_HOST, pszDst, &cbCap);
     62            if (RT_SUCCESS(rc))
     63                break;
    5964            *pszDst = '\0';
     65            if (rc != VERR_BUFFER_OVERFLOW)
     66                break;
     67            if (--cTries == 0)
     68                break;
     69            rc = rStrAbs.reserveNoThrow(RT_MIN(RT_ALIGN_Z(cbCap, 64), RTPATH_MAX));
     70            if (RT_FAILURE(rc))
     71                break;
     72        }
    6073        rStrAbs.jolt();
    6174    }
     
    6881 *
    6982 * @returns IPRT status code.
    70  * @param   rStrAbs         Reference to the destiation string.
     83 * @param   rStrAbs         Reference to the destination string.
    7184 * @param   rStrRelative    Reference to the relative source string.
    7285 */
     
    7790
    7891
     92
     93/**
     94 * RTPathAbsEx() wrapper for working directly on a RTCString instance.
     95 *
     96 * @returns IPRT status code.
     97 * @param   rStrAbs         Reference to the destination string.
     98 * @param   pszBase         The base path, optional.
     99 * @param   pszRelative     The relative source string.
     100 * @param   fFlags          RTPATH_STR_F_STYLE_XXX and RTPATHABS_F_XXX flags.
     101 */
     102DECLINLINE(int) RTPathAbsExCxx(RTCString &rStrAbs, const char *pszBase, const char *pszRelative, uint32_t fFlags = RTPATH_STR_F_STYLE_HOST)
     103{
     104    Assert(rStrAbs.c_str() != pszRelative);
     105    int rc = rStrAbs.reserveNoThrow(RTPATH_MAX);
     106    if (RT_SUCCESS(rc))
     107    {
     108        unsigned cTries = 8;
     109        for (;;)
     110        {
     111            char *pszDst = rStrAbs.mutableRaw();
     112            size_t cbCap = rStrAbs.capacity();
     113            rc = RTPathAbsEx(pszBase, pszRelative, fFlags, pszDst, &cbCap);
     114            if (RT_SUCCESS(rc))
     115                break;
     116            *pszDst = '\0';
     117            if (rc != VERR_BUFFER_OVERFLOW)
     118                break;
     119            if (--cTries == 0)
     120                break;
     121            rc = rStrAbs.reserveNoThrow(RT_MIN(RT_ALIGN_Z(cbCap, 64), RTPATH_MAX));
     122            if (RT_FAILURE(rc))
     123                break;
     124        }
     125        rStrAbs.jolt();
     126    }
     127    return rc;
     128}
     129
     130
     131DECLINLINE(int) RTPathAbsExCxx(RTCString &rStrAbs, RTCString const &rStrBase, RTCString const &rStrRelative, uint32_t fFlags = RTPATH_STR_F_STYLE_HOST)
     132{
     133    return RTPathAbsExCxx(rStrAbs, rStrBase.c_str(), rStrRelative.c_str(), fFlags);
     134}
     135
     136
     137DECLINLINE(int) RTPathAbsExCxx(RTCString &rStrAbs, const char *pszBase, RTCString const &rStrRelative, uint32_t fFlags = RTPATH_STR_F_STYLE_HOST)
     138{
     139    return RTPathAbsExCxx(rStrAbs, pszBase, rStrRelative.c_str(), fFlags);
     140}
     141
     142
     143DECLINLINE(int) RTPathAbsExCxx(RTCString &rStrAbs, RTCString const &rStrBase, const char *pszRelative, uint32_t fFlags = RTPATH_STR_F_STYLE_HOST)
     144{
     145    return RTPathAbsExCxx(rStrAbs, rStrBase.c_str(), pszRelative, fFlags);
     146}
     147
     148
     149
    79150/**
    80151 * RTPathAppPrivateNoArch() wrapper for working directly on a RTCString instance.
    81152 *
    82153 * @returns IPRT status code.
    83  * @param   rStrDst         Reference to the destiation string.
     154 * @param   rStrDst         Reference to the destination string.
    84155 */
    85156DECLINLINE(int) RTPathAppPrivateNoArchCxx(RTCString &rStrDst)
     
    103174 *
    104175 * @returns IPRT status code.
    105  * @param   rStrDst         Reference to the destiation string.
     176 * @param   rStrDst         Reference to the destination string.
    106177 * @param   pszAppend       One or more components to append to the path already
    107178 *                          present in @a rStrDst.
     
    135206 *
    136207 * @returns IPRT status code.
    137  * @param   rStrDst         Reference to the destiation string.
     208 * @param   rStrDst         Reference to the destination string.
    138209 * @param   rStrAppend      One or more components to append to the path already
    139210 *                          present in @a rStrDst.
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