VirtualBox

Changeset 21675 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jul 17, 2009 12:18:30 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
50224
Message:

IPRT: Moved rtPathVolumeSpecLen.

Location:
trunk/src/VBox/Runtime
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r21674 r21675  
    234234        common/misc/zip.cpp \
    235235        common/misc/term.cpp \
     236        common/path/rtPathVolumeSpecLen.cpp \
    236237        common/path/RTPathAbsDup.cpp \
    237238        common/path/RTPathAbsEx.cpp \
     
    724725        common/misc/sanity-c.c \
    725726        common/misc/sanity-cpp.cpp \
     727        common/path/rtPathVolumeSpecLen.cpp \
    726728        common/path/RTPathAbsDup.cpp \
    727729        common/path/RTPathAbsEx.cpp \
     
    11061108        common/misc/sanity-cpp.cpp \
    11071109        common/misc/term.cpp \
     1110        common/path/rtPathVolumeSpecLen.cpp \
    11081111        common/path/RTPathAbsDup.cpp \
     1112        common/path/RTPathAbsEx.cpp \
     1113        common/path/RTPathAbsExDup.cpp \
    11091114        common/path/RTPathAppend.cpp \
    11101115        common/path/RTPathExt.cpp \
  • trunk/src/VBox/Runtime/common/path/RTPathAbsEx.cpp

    r21673 r21675  
    3838#include <iprt/param.h>
    3939#include <iprt/string.h>
    40 #include "internal/fs.h"
     40#include "internal/path.h"
    4141
    42 
    43 
    44 /**
    45  * Returns the length of the volume name specifier of the given path.
    46  * If no such specifier zero is returned.
    47  */
    48 size_t rtPathVolumeSpecLen(const char *pszPath)
    49 {
    50 #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
    51     if (pszPath && *pszPath)
    52     {
    53         /* UTC path. */
    54         /** @todo r=bird: it's UNC and we have to check that the next char isn't a
    55          *        slash, then skip both the server and the share name. */
    56         if (    (pszPath[0] == '\\' || pszPath[0] == '/')
    57             &&  (pszPath[1] == '\\' || pszPath[1] == '/'))
    58             return strcspn(pszPath + 2, "\\/") + 2;
    59 
    60         /* Drive letter. */
    61         if (    pszPath[1] == ':'
    62             &&  toupper(pszPath[0]) >= 'A' && toupper(pszPath[0]) <= 'Z')
    63             return 2;
    64     }
    65     return 0;
    66 
    67 #else
    68     /* This isn't quite right when looking at the above stuff, but it works assuming that '//' does not mean UNC. */
    69     /// @todo (dmik) well, it's better to consider there's no volume name
    70     //  at all on *nix systems
    71     return 0;
    72 //    return pszPath && pszPath[0] == '/';
    73 #endif
    74 }
    7542
    7643
  • trunk/src/VBox/Runtime/common/path/rtPathVolumeSpecLen.cpp

    r21673 r21675  
    11/* $Id$ */
    22/** @file
    3  * IPRT - RTPathAbsEx
     3 * IPRT - rtPathVolumeSpecLen
    44 */
    55
     
    3434*******************************************************************************/
    3535#include "internal/iprt.h"
    36 #include <iprt/path.h>
    37 #include <iprt/err.h>
    38 #include <iprt/param.h>
    3936#include <iprt/string.h>
    40 #include "internal/fs.h"
     37#include "internal/path.h"
    4138
    4239
     
    7471}
    7572
    76 
    77 /**
    78  * Get the absolute path (no symlinks, no . or .. components), assuming the
    79  * given base path as the current directory. The resulting path doesn't have
    80  * to exist.
    81  *
    82  * @returns iprt status code.
    83  * @param   pszBase         The base path to act like a current directory.
    84  *                          When NULL, the actual cwd is used (i.e. the call
    85  *                          is equivalent to RTPathAbs(pszPath, ...).
    86  * @param   pszPath         The path to resolve.
    87  * @param   pszAbsPath      Where to store the absolute path.
    88  * @param   cchAbsPath      Size of the buffer.
    89  */
    90 RTDECL(int) RTPathAbsEx(const char *pszBase, const char *pszPath, char *pszAbsPath, size_t cchAbsPath)
    91 {
    92     if (pszBase && pszPath && !rtPathVolumeSpecLen(pszPath))
    93     {
    94 #if defined(RT_OS_WINDOWS)
    95         /* The format for very long paths is not supported. */
    96         if (    (pszBase[0] == '/' || pszBase[0] == '\\')
    97             &&  (pszBase[1] == '/' || pszBase[1] == '\\')
    98             &&   pszBase[2] == '?'
    99             &&  (pszBase[3] == '/' || pszBase[3] == '\\'))
    100             return VERR_INVALID_NAME;
    101 #endif
    102 
    103         /** @todo there are a couple of things which isn't 100% correct, although the
    104          * current code will have to work for now - I don't have time to fix it right now.
    105          *
    106          * 1) On Windows & OS/2 we confuse '/' with an abspath spec and will
    107          *    not necessarily resolve it on the right drive.
    108          * 2) A trailing slash in the base might cause UNC names to be created.
    109          * 3) The lengths total doesn't have to be less than max length
    110          *    if the pszPath starts with a slash.
    111          */
    112         size_t cchBase = strlen(pszBase);
    113         size_t cchPath = strlen(pszPath);
    114         if (cchBase + cchPath >= RTPATH_MAX)
    115             return VERR_FILENAME_TOO_LONG;
    116 
    117         bool fRootSpec = pszPath[0] == '/'
    118 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2)
    119             || pszPath[0] == '\\'
    120 #endif
    121             ;
    122         size_t cchVolSpec = rtPathVolumeSpecLen(pszBase);
    123         char szPath[RTPATH_MAX];
    124         if (fRootSpec)
    125         {
    126             /* join the disk name from base and the path */
    127             memcpy(szPath, pszBase, cchVolSpec);
    128             strcpy(&szPath[cchVolSpec], pszPath);
    129         }
    130         else
    131         {
    132             /* join the base path and the path */
    133             strcpy(szPath, pszBase);
    134             szPath[cchBase] = RTPATH_DELIMITER;
    135             strcpy(&szPath[cchBase + 1], pszPath);
    136         }
    137         return RTPathAbs(szPath, pszAbsPath, cchAbsPath);
    138     }
    139 
    140     /* Fallback to the non *Ex version */
    141     return RTPathAbs(pszPath, pszAbsPath, cchAbsPath);
    142 }
    143 
  • trunk/src/VBox/Runtime/include/internal/fs.h

    r20374 r21675  
    4545bool    rtFsModeIsValidPermissions(RTFMODE fMode);
    4646
    47 size_t  rtPathVolumeSpecLen(const char *pszPath);
    4847#ifndef RT_OS_WINDOWS
    4948void    rtFsConvertStatToObjInfo(PRTFSOBJINFO pObjInfo, const struct stat *pStat, const char *pszName, unsigned cbName);
  • trunk/src/VBox/Runtime/include/internal/path.h

    r20374 r21675  
    4343
    4444
    45 int rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType);
    46 int rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType);
     45size_t  rtPathVolumeSpecLen(const char *pszPath);
     46int     rtPathPosixRename(const char *pszSrc, const char *pszDst, unsigned fRename, RTFMODE fFileType);
     47int     rtPathWin32MoveRename(const char *pszSrc, const char *pszDst, uint32_t fFlags, RTFMODE fFileType);
    4748
    4849
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r21486 r21675  
    5252#include <iprt/assert.h>
    5353#include <iprt/uni.h>
    54 #include "internal/fs.h"
    5554#include "internal/dir.h"
     55#include "internal/path.h"
    5656
    5757
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