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