dir.cpp revision 1c94c0a63ba68be1a7b2c640e70d7a06464e4fca
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * innotek Portable Runtime - Directory Manipulation.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * available from http://www.virtualbox.org. This file is free software;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * you can redistribute it and/or modify it under the terms of the GNU
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * General Public License (GPL) as published by the Free Software
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * The contents of this file may alternatively be used under the terms
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * of the Common Development and Distribution License Version 1.0
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * VirtualBox OSE distribution, in which case the provisions of the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * CDDL are applicable instead of those of the GPL.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * You may elect to license modified versions of this file under the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * terms and conditions of either the GPL or the CDDL or both.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * additional information or have any questions.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/*******************************************************************************
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync* Header Files *
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync*******************************************************************************/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatch(PRTDIR pDir, const char *pszName);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatchNoWildcards(PRTDIR pDir, const char *pszName);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncDECLINLINE(bool) rtDirFilterWinNtMatchEon(PCRTUNICP puszFilter);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic bool rtDirFilterWinNtMatchDosStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic bool rtDirFilterWinNtMatchStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic bool rtDirFilterWinNtMatchBase(unsigned iDepth, const char *pszName, PCRTUNICP puszFilter);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncRTDECL(int) RTDirCreateFullPath(const char *pszPath, RTFMODE fMode)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Resolve the path.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync int rc = RTPathAbs(pszPath, szAbsPath, sizeof(szAbsPath));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Iterate the path components making sure each of them exists.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /* skip volume name */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync char *psz = &szAbsPath[rtPathVolumeSpecLen(szAbsPath)];
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /* skip the root slash if any */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /* iterate over path components. */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync /* the next component is NULL, stop iterating */
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * ASSUME that RTDirCreate will return VERR_ALREADY_EXISTS and not VERR_ACCESS_DENIED in those cases
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * where the directory exists but we don't have write access to the parent directory.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Filter a the filename in the against a filter.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * @returns true if the name matches the filter.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * @returns false if the name doesn't match filter.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * @param pDir The directory handle.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * @param pszName The path to match to the filter.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncstatic DECLCALLBACK(bool) rtDirFilterWinNtMatchNoWildcards(PRTDIR pDir, const char *pszName)
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Walk the string and compare.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync return false;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync return true;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Matches end of name.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncDECLINLINE(bool) rtDirFilterWinNtMatchEon(PCRTUNICP puszFilter)
static bool rtDirFilterWinNtMatchDosStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter)
if (!pszDosDot)
switch (ucFilter)
puszFilter--;
static bool rtDirFilterWinNtMatchStar(unsigned iDepth, RTUNICP uc, const char *pszNext, PCRTUNICP puszFilter)
switch (ucFilter)
puszFilter++;
if (!uc)
} while (--cQms > 0);
if (!ucFilter)
} while (uc);
} while (uc);
} while (uc);
switch (ucFilter)
if (!uc)
if (!uc)
puszFilter++;
++puszFilter;
if (uc)
} while (uc);
return NULL;
bool fHaveWildcards = false;
unsigned iRead = 0;
unsigned iWrite = 0;
fHaveWildcards = true;
iRead++;
fHaveWildcards = true;
return fHaveWildcards
static int rtDirOpenCommon(PRTDIR *ppDir, const char *pszPath, const char *pszFilter, RTDIRFILTER enmFilter)
int rc;
if (!pszFilter)
if (!pszTmp)
return VERR_NO_MEMORY;
return rc;
PRTDIR pDir = (PRTDIR)RTMemAlloc(sizeof(RTDIR) + cchRealPath + 1 + 4 + cchFilter + cucFilter * sizeof(RTUNICP));
if (!pDir)
return VERR_NO_MEMORY;
if (cchFilter)
switch (enmFilter)
case RTDIRFILTER_NONE:
case RTDIRFILTER_WINNT:
case RTDIRFILTER_UNIX:
case RTDIRFILTER_UNIX_UPCASED:
#ifndef RT_DONT_CONVERT_FILENAMES
return rc;
return rc;
switch (enmFilter)
case RTDIRFILTER_UNIX:
case RTDIRFILTER_UNIX_UPCASED:
return VERR_NOT_IMPLEMENTED;
case RTDIRFILTER_NONE:
case RTDIRFILTER_WINNT:
: NULL;
return rc;