077137f1c602268ce62c760701f619a2ae929923vboxsync/* $Id$ */
077137f1c602268ce62c760701f619a2ae929923vboxsync/** @file
077137f1c602268ce62c760701f619a2ae929923vboxsync * IPRT - rtPathVolumeSpecLen
077137f1c602268ce62c760701f619a2ae929923vboxsync */
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2012 Oracle Corporation
077137f1c602268ce62c760701f619a2ae929923vboxsync *
077137f1c602268ce62c760701f619a2ae929923vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
077137f1c602268ce62c760701f619a2ae929923vboxsync * available from http://www.virtualbox.org. This file is free software;
077137f1c602268ce62c760701f619a2ae929923vboxsync * you can redistribute it and/or modify it under the terms of the GNU
077137f1c602268ce62c760701f619a2ae929923vboxsync * General Public License (GPL) as published by the Free Software
077137f1c602268ce62c760701f619a2ae929923vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
077137f1c602268ce62c760701f619a2ae929923vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
077137f1c602268ce62c760701f619a2ae929923vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
077137f1c602268ce62c760701f619a2ae929923vboxsync *
077137f1c602268ce62c760701f619a2ae929923vboxsync * The contents of this file may alternatively be used under the terms
077137f1c602268ce62c760701f619a2ae929923vboxsync * of the Common Development and Distribution License Version 1.0
077137f1c602268ce62c760701f619a2ae929923vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
077137f1c602268ce62c760701f619a2ae929923vboxsync * VirtualBox OSE distribution, in which case the provisions of the
077137f1c602268ce62c760701f619a2ae929923vboxsync * CDDL are applicable instead of those of the GPL.
077137f1c602268ce62c760701f619a2ae929923vboxsync *
077137f1c602268ce62c760701f619a2ae929923vboxsync * You may elect to license modified versions of this file under the
077137f1c602268ce62c760701f619a2ae929923vboxsync * terms and conditions of either the GPL or the CDDL or both.
077137f1c602268ce62c760701f619a2ae929923vboxsync */
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync/*******************************************************************************
077137f1c602268ce62c760701f619a2ae929923vboxsync* Header Files *
077137f1c602268ce62c760701f619a2ae929923vboxsync*******************************************************************************/
077137f1c602268ce62c760701f619a2ae929923vboxsync#include "internal/iprt.h"
077137f1c602268ce62c760701f619a2ae929923vboxsync#include <iprt/string.h>
73faa4fdf1520bc23e5ee3ee044781c0aa11a6a0vboxsync#include <iprt/ctype.h>
077137f1c602268ce62c760701f619a2ae929923vboxsync#include "internal/path.h"
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync/**
077137f1c602268ce62c760701f619a2ae929923vboxsync * Returns the length of the volume name specifier of the given path.
077137f1c602268ce62c760701f619a2ae929923vboxsync * If no such specifier zero is returned.
077137f1c602268ce62c760701f619a2ae929923vboxsync */
b6cc4092c1e80655a5bc19dc125e772a8d2b870dvboxsyncDECLHIDDEN(size_t) rtPathVolumeSpecLen(const char *pszPath)
077137f1c602268ce62c760701f619a2ae929923vboxsync{
077137f1c602268ce62c760701f619a2ae929923vboxsync#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
077137f1c602268ce62c760701f619a2ae929923vboxsync if (pszPath && *pszPath)
077137f1c602268ce62c760701f619a2ae929923vboxsync {
b6b40d21fb1ce43de5586f09e3469f17c06d4d88vboxsync /* UNC path. */
077137f1c602268ce62c760701f619a2ae929923vboxsync /** @todo r=bird: it's UNC and we have to check that the next char isn't a
077137f1c602268ce62c760701f619a2ae929923vboxsync * slash, then skip both the server and the share name. */
077137f1c602268ce62c760701f619a2ae929923vboxsync if ( (pszPath[0] == '\\' || pszPath[0] == '/')
077137f1c602268ce62c760701f619a2ae929923vboxsync && (pszPath[1] == '\\' || pszPath[1] == '/'))
077137f1c602268ce62c760701f619a2ae929923vboxsync return strcspn(pszPath + 2, "\\/") + 2;
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync /* Drive letter. */
077137f1c602268ce62c760701f619a2ae929923vboxsync if ( pszPath[1] == ':'
1d4b0322a1bef79fc1839445a3712141c5bb3f46vboxsync && RT_C_IS_ALPHA(pszPath[0]))
077137f1c602268ce62c760701f619a2ae929923vboxsync return 2;
077137f1c602268ce62c760701f619a2ae929923vboxsync }
077137f1c602268ce62c760701f619a2ae929923vboxsync return 0;
077137f1c602268ce62c760701f619a2ae929923vboxsync
077137f1c602268ce62c760701f619a2ae929923vboxsync#else
077137f1c602268ce62c760701f619a2ae929923vboxsync /* This isn't quite right when looking at the above stuff, but it works assuming that '//' does not mean UNC. */
077137f1c602268ce62c760701f619a2ae929923vboxsync /// @todo (dmik) well, it's better to consider there's no volume name
077137f1c602268ce62c760701f619a2ae929923vboxsync // at all on *nix systems
4e47bb772df0d04d1ded3e06354de547d52e2d06vboxsync NOREF(pszPath);
077137f1c602268ce62c760701f619a2ae929923vboxsync return 0;
077137f1c602268ce62c760701f619a2ae929923vboxsync// return pszPath && pszPath[0] == '/';
077137f1c602268ce62c760701f619a2ae929923vboxsync#endif
077137f1c602268ce62c760701f619a2ae929923vboxsync}
077137f1c602268ce62c760701f619a2ae929923vboxsync