e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync/* $Id$ */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync/** @file
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * IPRT - RTPathTraverseList
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2009-2010 Oracle Corporation
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync *
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * available from http://www.virtualbox.org. This file is free software;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * you can redistribute it and/or modify it under the terms of the GNU
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * General Public License (GPL) as published by the Free Software
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync *
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * The contents of this file may alternatively be used under the terms
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * of the Common Development and Distribution License Version 1.0
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * VirtualBox OSE distribution, in which case the provisions of the
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * CDDL are applicable instead of those of the GPL.
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync *
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * You may elect to license modified versions of this file under the
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * terms and conditions of either the GPL or the CDDL or both.
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync/*******************************************************************************
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync* Header Files *
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync*******************************************************************************/
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync#include "internal/iprt.h"
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync#include <iprt/path.h>
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync#include <iprt/assert.h>
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync#include <iprt/ctype.h>
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync#include <iprt/err.h>
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync#include <iprt/string.h>
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsyncRTDECL(int) RTPathTraverseList(const char *pszPathList, char chSep, PFNRTPATHTRAVERSER pfnCallback, void *pvUser1, void *pvUser2)
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync{
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync AssertPtrNull(pszPathList);
bd70ce265a86fbcc7426390f7129a30fde0009d3vboxsync Assert((unsigned int)chSep <= 127);
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync if (!pszPathList)
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync return VERR_END_OF_STRING;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync /*
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync * Walk the path list.
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync const char *psz = pszPathList;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync while (*psz)
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync {
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync /* Skip leading blanks - no directories with leading spaces, thank you. */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync while (RT_C_IS_BLANK(*psz))
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync psz++;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync /* Find the end of this element. */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync const char *pszNext;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync const char *pszEnd = strchr(psz, chSep);
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync if (!pszEnd)
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync pszEnd = pszNext = strchr(psz, '\0');
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync else
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync pszNext = pszEnd + 1;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync if (pszEnd != psz)
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync {
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync size_t const cch = pszEnd - psz;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync int rc = pfnCallback(psz, cch, pvUser1, pvUser2);
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync if (rc != VERR_TRY_AGAIN)
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync return rc;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync }
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync /* advance */
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync psz = pszNext;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync }
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync return VERR_END_OF_STRING;
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync}
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsyncRT_EXPORT_SYMBOL(RTPathTraverseList);
e3b4dbc12a564912424d8e10528b6a98c8bf76b1vboxsync