RTPathParse.cpp.h revision 889f8d29a8325ed741d1466074c5371910a1fd63
af062818b47340eef15700d2f0211576ba3506eevboxsync * IPRT - RTPathParse - Code Template.
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file included multiple times with different path style macros.
af062818b47340eef15700d2f0211576ba3506eevboxsync * Copyright (C) 2006-2013 Oracle Corporation
af062818b47340eef15700d2f0211576ba3506eevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
af062818b47340eef15700d2f0211576ba3506eevboxsync * available from http://www.virtualbox.org. This file is free software;
af062818b47340eef15700d2f0211576ba3506eevboxsync * you can redistribute it and/or modify it under the terms of the GNU
af062818b47340eef15700d2f0211576ba3506eevboxsync * General Public License (GPL) as published by the Free Software
af062818b47340eef15700d2f0211576ba3506eevboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
af062818b47340eef15700d2f0211576ba3506eevboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
af062818b47340eef15700d2f0211576ba3506eevboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * The contents of this file may alternatively be used under the terms
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * of the Common Development and Distribution License Version 1.0
4b9d6701570cb98fd36e209314239d104ec584d3vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * VirtualBox OSE distribution, in which case the provisions of the
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * CDDL are applicable instead of those of the GPL.
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * You may elect to license modified versions of this file under the
b955672b950093ff7416d1269dd4d3b69983bd8fvboxsync * terms and conditions of either the GPL or the CDDL or both.
af062818b47340eef15700d2f0211576ba3506eevboxsync * @copydoc RTPathParse
af062818b47340eef15700d2f0211576ba3506eevboxsyncstatic int RTPATH_STYLE_FN(rtPathParse)(const char *pszPath, PRTPATHPARSED pParsed, size_t cbParsed, uint32_t fFlags)
af062818b47340eef15700d2f0211576ba3506eevboxsync * Parse the root specification if present and initialize the parser state
af062818b47340eef15700d2f0211576ba3506eevboxsync * (keep it on the stack for speed).
af062818b47340eef15700d2f0211576ba3506eevboxsync uint32_t const cMaxComps = cbParsed < RT_UOFFSETOF(RTPATHPARSED, aComps[0xfff0])
af062818b47340eef15700d2f0211576ba3506eevboxsync ? (cbParsed - RT_UOFFSETOF(RTPATHPARSED, aComps)) / sizeof(pParsed->aComps[0])
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_RELATIVE | RTPATH_PROP_EXTRA_SLASHES;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* UNC - skip to the end of the potential namespace or computer name. */
af062818b47340eef15700d2f0211576ba3506eevboxsync while (!RTPATH_IS_SLASH(pszPath[offCur]) && pszPath[offCur])
af062818b47340eef15700d2f0211576ba3506eevboxsync /* If there is another slash, we considered it a valid UNC path, if
af062818b47340eef15700d2f0211576ba3506eevboxsync not it's just a root path with an extra slash thrown in. */
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_UNC | RTPATH_PROP_ABSOLUTE;
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_RELATIVE;
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_RELATIVE;
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_ABSOLUTE;
af062818b47340eef15700d2f0211576ba3506eevboxsync else if (RT_C_IS_ALPHA(pszPath[0]) && pszPath[1] == ':')
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_VOLUME | RTPATH_PROP_RELATIVE;
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps = RTPATH_PROP_VOLUME | RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_ABSOLUTE;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Add it to the component array . */
af062818b47340eef15700d2f0211576ba3506eevboxsync if (offCur && !(fFlags & RTPATHPARSE_FLAGS_NO_START))
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Skip unnecessary slashes following the root-spec. */
af062818b47340eef15700d2f0211576ba3506eevboxsync * Parse the rest.
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Find the end of the component. */
af062818b47340eef15700d2f0211576ba3506eevboxsync while ((ch = pszPath[offCur]) != '\0' && !RTPATH_IS_SLASH(ch))
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Add it. */
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Look for '.' and '..' references. */
af062818b47340eef15700d2f0211576ba3506eevboxsync else if (cchComp == 2 && pszPath[offCur - 1] == '.' && pszPath[offCur - 2] == '.')
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps |= RTPATH_PROP_DOTDOT_REFS | RTPATH_PROP_RELATIVE;
af062818b47340eef15700d2f0211576ba3506eevboxsync /* Skip unnecessary slashes. Leave ch unchanged! */
af062818b47340eef15700d2f0211576ba3506eevboxsync /* The end? */
af062818b47340eef15700d2f0211576ba3506eevboxsync fProps |= RTPATH_PROP_DIR_SLASH; /* (not counted) */
return VERR_FILENAME_TOO_LONG;