VirtualBox

Ignore:
Timestamp:
Sep 16, 2019 6:10:52 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133402
Message:

IPRT: Added RTPathEnsureTrailingSeparatorEx.

File:
1 edited

Legend:

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

    r76553 r80832  
    11/* $Id$ */
    22/** @file
    3  * IPRT - RTPathEnsureTrailingSeparator
     3 * IPRT - RTPathEnsureTrailingSeparator & RTPathEnsureTrailingSeparatorEx
    44 */
    55
     
    3131#include "internal/iprt.h"
    3232#include <iprt/path.h>
     33
     34#include <iprt/assert.h>
     35#include <iprt/ctype.h>
    3336#include <iprt/string.h>
    34 #include <iprt/ctype.h>
    3537
    3638
     39/*********************************************************************************************************************************
     40*   Global Variables                                                                                                             *
     41*********************************************************************************************************************************/
     42/** Slash character indexed by path style. */
     43static char g_achSlashes[] =
     44{
     45    /*[RTPATH_STR_F_STYLE_HOST] =*/     RTPATH_SLASH,
     46    /*[RTPATH_STR_F_STYLE_DOS] =*/      '\\',
     47    /*[RTPATH_STR_F_STYLE_UNIX] =*/     '/',
     48    /*[RTPATH_STR_F_STYLE_RESERVED] =*/ '!',
     49};
     50AssertCompile(RTPATH_STR_F_STYLE_HOST == 0);
     51AssertCompile(RTPATH_STR_F_STYLE_DOS  == 1);
     52AssertCompile(RTPATH_STR_F_STYLE_UNIX == 2);
    3753
    38 RTDECL(size_t) RTPathEnsureTrailingSeparator(char *pszPath, size_t cbPath)
     54
     55RTDECL(size_t) RTPathEnsureTrailingSeparatorEx(char *pszPath, size_t cbPath, uint32_t fFlags)
    3956{
     57    Assert(RTPATH_STR_F_IS_VALID(fFlags, 0));
     58
    4059    size_t off = strlen(pszPath);
    4160    if (off > 0)
    4261    {
    4362        char ch = pszPath[off - 1];
    44         if (RTPATH_IS_SLASH(ch) || RTPATH_IS_VOLSEP(ch))
     63        if (ch == '/')
    4564            return off;
     65        if (   (ch == ':' || ch == '\\')
     66            && (   (fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_DOS
     67#if RTPATH_STYLE == RTPATH_STR_F_STYLE_DOS
     68                || (fFlags & RTPATH_STR_F_STYLE_MASK) == RTPATH_STR_F_STYLE_HOST
     69#endif
     70               ))
     71            return off;
     72
    4673        if (off + 2 <= cbPath)
    4774        {
    48             pszPath[off++] = RTPATH_SLASH;
     75            pszPath[off++] = g_achSlashes[fFlags & RTPATH_STR_F_STYLE_MASK];
    4976            pszPath[off]   = '\0';
    5077            return off;
     
    5481    {
    5582        pszPath[off++] = '.';
    56         pszPath[off++] = RTPATH_SLASH;
     83        pszPath[off++] =  g_achSlashes[fFlags & RTPATH_STR_F_STYLE_MASK];
    5784        pszPath[off]   = '\0';
    5885        return off;
     
    6188    return 0;
    6289}
     90RT_EXPORT_SYMBOL(RTPathEnsureTrailingSeparatorEx);
     91
     92
     93RTDECL(size_t) RTPathEnsureTrailingSeparator(char *pszPath, size_t cbPath)
     94{
     95    return RTPathEnsureTrailingSeparatorEx(pszPath, cbPath, RTPATH_STR_F_STYLE_HOST);
     96}
    6397RT_EXPORT_SYMBOL(RTPathEnsureTrailingSeparator);
    6498
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