b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync/* $Id$ */
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync/** @file
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * IPRT - RTPathCountComponents
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync */
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2010 Oracle Corporation
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync *
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * available from http://www.virtualbox.org. This file is free software;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * you can redistribute it and/or modify it under the terms of the GNU
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * General Public License (GPL) as published by the Free Software
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync *
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * The contents of this file may alternatively be used under the terms
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * of the Common Development and Distribution License Version 1.0
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * VirtualBox OSE distribution, in which case the provisions of the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * CDDL are applicable instead of those of the GPL.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync *
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * You may elect to license modified versions of this file under the
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync * terms and conditions of either the GPL or the CDDL or both.
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync */
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync/*******************************************************************************
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync* Header Files *
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync*******************************************************************************/
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync#include "internal/iprt.h"
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync#include <iprt/path.h>
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync#include <iprt/assert.h>
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync#include "internal/path.h"
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsyncRTDECL(size_t) RTPathCountComponents(const char *pszPath)
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync{
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync size_t off = rtPathRootSpecLen(pszPath);
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync size_t c = off != 0;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync while (pszPath[off])
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync {
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync c++;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync while (!RTPATH_IS_SLASH(pszPath[off]) && pszPath[off])
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync off++;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync while (RTPATH_IS_SLASH(pszPath[off]))
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync off++;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync }
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync return c;
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync}
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsync