VirtualBox

Ignore:
Timestamp:
Nov 19, 2010 5:18:15 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67956
Message:

IPRT: Added RTPathJoinEx and RTPathAppendEx.

File:
1 copied

Legend:

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

    r34201 r34214  
    11/* $Id$ */
    22/** @file
    3  * IPRT - RTPathAppend
     3 * IPRT - RTPathAppendEx
    44 */
    55
    66/*
    7  * Copyright (C) 2009 Oracle Corporation
     7 * Copyright (C) 2009-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    105105
    106106
    107 RTDECL(int) RTPathAppend(char *pszPath, size_t cbPathDst, const char *pszAppend)
     107RTDECL(int) RTPathAppendEx(char *pszPath, size_t cbPathDst, const char *pszAppend, size_t cchAppendMax)
    108108{
    109109    char *pszPathEnd = RTStrEnd(pszPath, cbPathDst);
     
    115115    if (!pszAppend)
    116116        return VINF_SUCCESS;
    117     size_t cchAppend = strlen(pszAppend);
     117    size_t cchAppend = RTStrNLen(pszAppend, cchAppendMax);
    118118    if (!cchAppend)
    119119        return VINF_SUCCESS;
     
    122122        if (cchAppend >= cbPathDst)
    123123            return VERR_BUFFER_OVERFLOW;
    124         memcpy(pszPath, pszAppend, cchAppend + 1);
     124        memcpy(pszPath, pszAppend, cchAppend);
     125        pszPath[cchAppend] = '\0';
    125126        return VINF_SUCCESS;
    126127    }
     
    153154        {
    154155            /* One slash is sufficient at this point. */
    155             while (RTPATH_IS_SLASH(pszAppend[1]))
     156            while (cchAppend > 1 && RTPATH_IS_SLASH(pszAppend[1]))
    156157                pszAppend++, cchAppend--;
    157158
     
    163164    {
    164165        /* No slashes needed in the appended bit. */
    165         while (RTPATH_IS_SLASH(*pszAppend))
     166        while (cchAppend && RTPATH_IS_SLASH(*pszAppend))
    166167            pszAppend++, cchAppend--;
    167168
     
    180181     * What remains now is the just the copying.
    181182     */
    182     memcpy(pszPathEnd, pszAppend, cchAppend + 1);
     183    memcpy(pszPathEnd, pszAppend, cchAppend);
     184    pszPathEnd[cchAppend] = '\0';
    183185    return VINF_SUCCESS;
    184186}
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