RTPathSplitReassemble.cpp revision 448991352053bf9c3ca8789439a4e1329cc34ba0
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * IPRT - RTPathSplitReassemble.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * Copyright (C) 2013 Oracle Corporation
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * available from http://www.virtualbox.org. This file is free software;
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * you can redistribute it and/or modify it under the terms of the GNU
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * General Public License (GPL) as published by the Free Software
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * The contents of this file may alternatively be used under the terms
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * of the Common Development and Distribution License Version 1.0
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * VirtualBox OSE distribution, in which case the provisions of the
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * CDDL are applicable instead of those of the GPL.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * You may elect to license modified versions of this file under the
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * terms and conditions of either the GPL or the CDDL or both.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync/*******************************************************************************
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync* Header Files *
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync*******************************************************************************/
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsyncRTDECL(int) RTPathSplitReassemble(PRTPATHSPLIT pSplit, uint32_t fFlags, char *pszDstPath, size_t cbDstPath)
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * Input validation.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync AssertReturn(pSplit->cComps > 0, VERR_INVALID_PARAMETER);
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync AssertReturn(RTPATH_STR_F_IS_VALID(fFlags, 0) && !(fFlags & RTPATH_STR_F_MIDDLE), VERR_INVALID_FLAGS);
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync AssertReturn(cbDstPath > pSplit->cchPath, VERR_BUFFER_OVERFLOW);
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * Figure which slash to use.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync AssertFailedReturn(VERR_INVALID_FLAGS); /* impossible */
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync * Do the joining.
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync AssertReturn(cchDstPath <= cchOrgPath, VERR_INVALID_PARAMETER);
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync /* fix the slashes */
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync while (cchComp-- > 0)
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync AssertReturn(cchDstPath <= cchOrgPath, VERR_INVALID_PARAMETER);
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync memcpy(pszDst, pSplit->apszComps[idxComp], cchComp);
448991352053bf9c3ca8789439a4e1329cc34ba0vboxsync if (idxComp != cComps || (pSplit->fProps & RTPATH_PROP_DIR_SLASH))