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