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