VirtualBox

Changeset 46008 in vbox


Ignore:
Timestamp:
May 13, 2013 11:05:55 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
85671
Message:

iprt/dir.h,++: Added RTDirQueryUnknownType, RTDirQueryUnknownTypeEx, RTDirEntryIsStdDotLink and RTDirEntryExIsStdDotLink to simplify directory enumeration.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/dir.h

    r44528 r46008  
    273273     * systems (or Unixes) stores the type of a directory entry and instead
    274274     * expects the user to use stat() to get it.  So, when you see this you
    275      * should use RTPathQueryInfo to get the type, or if if you're lazy, use
    276      * RTDirReadEx. */
     275     * should use RTDirQueryUnknownType or RTDirQueryUnknownTypeEx to get the type,
     276     * or if if you're lazy, use RTDirReadEx. */
    277277    RTDIRENTRYTYPE  enmType;
    278278    /** The length of the filename, excluding the terminating nul character. */
     
    285285/** Pointer to a directory entry. */
    286286typedef RTDIRENTRY *PRTDIRENTRY;
     287/** Pointer to a const directory entry. */
     288typedef RTDIRENTRY const *PCRTDIRENTRY;
    287289
    288290
     
    314316/** Pointer to a directory entry. */
    315317typedef RTDIRENTRYEX *PRTDIRENTRYEX;
     318/** Pointer to a const directory entry. */
     319typedef RTDIRENTRYEX const *PCRTDIRENTRYEX;
    316320
    317321
     
    410414RTDECL(int) RTDirReadEx(PRTDIR pDir, PRTDIRENTRYEX pDirEntry, size_t *pcbDirEntry, RTFSOBJATTRADD enmAdditionalAttribs, uint32_t fFlags);
    411415
     416/**
     417 * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead.
     418 *
     419 * @returns IPRT status code (see RTPathQueryInfo).
     420 * @param   pszComposedName The path to the directory entry. The caller must
     421 *                          compose this, it's NOT sufficient to pass
     422 *                          RTDIRENTRY::szName!
     423 * @param   penmType        Pointer to the RTDIRENTRY::enmType member.  If this
     424 *                          is not RTDIRENTRYTYPE_UNKNOWN, the function will
     425 *                          return immediately without doing anything.  If it
     426 *                          is, it will use RTPathQueryInfo to try figure out
     427 *                          the correct value.  On failure, this will be
     428 *                          unchanged.
     429 */
     430RTDECL(int) RTDirQueryUnknownType(const char *pszComposedName, RTDIRENTRYTYPE *penmType);
     431
     432/**
     433 * Resolves RTDIRENTRYTYPE_UNKNOWN values returned by RTDirRead, extended
     434 * version.
     435 *
     436 * @returns IPRT status code (see RTPathQueryInfo).
     437 * @param   pszComposedName The path to the directory entry. The caller must
     438 *                          compose this, it's NOT sufficient to pass
     439 *                          RTDIRENTRY::szName!
     440 * @param   penmType        Pointer to the RTDIRENTRY::enmType member or
     441 *                          similar.  Will NOT be checked on input.
     442 * @param   pObjInfo        The object info buffer to use with RTPathQueryInfo.
     443 */
     444RTDECL(int) RTDirQueryUnknownTypeEx(const char *pszComposedName, RTDIRENTRYTYPE *penmType, PRTFSOBJINFO pObjInfo);
     445
     446/**
     447 * Checks if the directory entry returned by RTDirRead is '.', '..' or similar.
     448 *
     449 * @returns true / false.
     450 * @param   pDirEntry       The directory entry to check.
     451 */
     452RTDECL(bool) RTDirEntryIsStdDotLink(PRTDIRENTRY pDirEntry);
     453
     454/**
     455 * Checks if the directory entry returned by RTDirReadEx is '.', '..' or
     456 * similar.
     457 *
     458 * @returns true / false.
     459 * @param   pDirEntryEx     The extended directory entry to check.
     460 */
     461RTDECL(bool) RTDirEntryExIsStdDotLink(PCRTDIRENTRYEX pDirEntryEx);
    412462
    413463/**
  • trunk/include/iprt/mangling.h

    r45994 r46008  
    426426# define RTDirCreateTempSecure                          RT_MANGLER(RTDirCreateTempSecure)
    427427# define RTDirCreateUniqueNumbered                      RT_MANGLER(RTDirCreateUniqueNumbered)
     428# define RTDirEntryIsStdDotLink                         RT_MANGLER(RTDirEntryIsStdDotLink)
     429# define RTDirEntryExIsStdDotLink                       RT_MANGLER(RTDirEntryExIsStdDotLink)
    428430# define RTDirExists                                    RT_MANGLER(RTDirExists)
    429431# define RTDirFlush                                     RT_MANGLER(RTDirFlush)
     
    432434# define RTDirOpenFiltered                              RT_MANGLER(RTDirOpenFiltered)
    433435# define RTDirQueryInfo                                 RT_MANGLER(RTDirQueryInfo)
     436# define RTDirQueryUnknownType                          RT_MANGLER(RTDirQueryUnknownType)
     437# define RTDirQueryUnknownTypeEx                        RT_MANGLER(RTDirQueryUnknownTypeEx)
    434438# define RTDirRead                                      RT_MANGLER(RTDirRead)
    435439# define RTDirReadEx                                    RT_MANGLER(RTDirReadEx)
  • trunk/src/VBox/Runtime/r3/dir.cpp

    r45630 r46008  
    731731}
    732732
     733
     734RTDECL(int) RTDirQueryUnknownTypeEx(const char *pszComposedName, RTDIRENTRYTYPE *penmType, PRTFSOBJINFO pObjInfo)
     735{
     736    int rc = RTPathQueryInfoEx(pszComposedName, pObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_ON_LINK);
     737    if (RT_FAILURE(rc))
     738        return rc;
     739
     740    if (RTFS_IS_DIRECTORY(pObjInfo->Attr.fMode))
     741        *penmType = RTDIRENTRYTYPE_DIRECTORY;
     742    else if (RTFS_IS_FILE(pObjInfo->Attr.fMode))
     743        *penmType = RTDIRENTRYTYPE_FILE;
     744    else if (RTFS_IS_SYMLINK(pObjInfo->Attr.fMode))
     745        *penmType = RTDIRENTRYTYPE_SYMLINK;
     746    else if (RTFS_IS_FIFO(pObjInfo->Attr.fMode))
     747        *penmType = RTDIRENTRYTYPE_FIFO;
     748    else if (RTFS_IS_DEV_CHAR(pObjInfo->Attr.fMode))
     749        *penmType = RTDIRENTRYTYPE_DEV_CHAR;
     750    else if (RTFS_IS_DEV_BLOCK(pObjInfo->Attr.fMode))
     751        *penmType = RTDIRENTRYTYPE_DEV_BLOCK;
     752    else if (RTFS_IS_SOCKET(pObjInfo->Attr.fMode))
     753        *penmType = RTDIRENTRYTYPE_SOCKET;
     754    else if (RTFS_IS_WHITEOUT(pObjInfo->Attr.fMode))
     755        *penmType = RTDIRENTRYTYPE_WHITEOUT;
     756    else
     757        *penmType = RTDIRENTRYTYPE_UNKNOWN;
     758
     759    return VINF_SUCCESS;
     760}
     761
     762
     763RTDECL(int) RTDirQueryUnknownType(const char *pszComposedName, RTDIRENTRYTYPE *penmType)
     764{
     765    if (*penmType != RTDIRENTRYTYPE_UNKNOWN)
     766        return VINF_SUCCESS;
     767
     768    RTFSOBJINFO ObjInfo;
     769    return RTDirQueryUnknownTypeEx(pszComposedName, penmType, &ObjInfo);
     770}
     771
     772
     773RTDECL(bool) RTDirEntryIsStdDotLink(PRTDIRENTRY pDirEntry)
     774{
     775    if (pDirEntry->szName[0] != '.')
     776        return false;
     777    if (pDirEntry->cbName == 1)
     778        return true;
     779    if (pDirEntry->cbName != 2)
     780        return false;
     781    return pDirEntry->szName[1] == '.';
     782}
     783
     784
     785RTDECL(bool) RTDirEntryExIsStdDotLink(PCRTDIRENTRYEX pDirEntryEx)
     786{
     787    if (pDirEntryEx->szName[0] != '.')
     788        return false;
     789    if (pDirEntryEx->cbName == 1)
     790        return true;
     791    if (pDirEntryEx->cbName != 2)
     792        return false;
     793    return pDirEntryEx->szName[1] == '.';
     794}
     795
  • trunk/src/VBox/Runtime/r3/win/fs-win.cpp

    r44528 r46008  
    320320        pProperties->fSupportsUnicode = !!(dwFlags & FILE_UNICODE_ON_DISK);
    321321        pProperties->fCaseSensitive   = false;    /* win32 is case preserving only */
     322        /** @todo r=bird: What about FILE_CASE_SENSITIVE_SEARCH ?  Is this set for NTFS
     323         *        as well perchance?  If so, better mention it instead of just setting
     324         *        fCaseSensitive to false. */
    322325        pProperties->fRemote          = false;    /* no idea yet */
    323326    }
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