c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync/* $Id$ */
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync/** @file
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * IPRT - RTPathJoinEx.
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync */
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync/*
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * Copyright (C) 2010 Oracle Corporation
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync *
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * available from http://www.virtualbox.org. This file is free software;
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * General Public License (GPL) as published by the Free Software
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync *
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * The contents of this file may alternatively be used under the terms
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * of the Common Development and Distribution License Version 1.0
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * CDDL are applicable instead of those of the GPL.
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync *
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * You may elect to license modified versions of this file under the
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * terms and conditions of either the GPL or the CDDL or both.
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync */
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync/*******************************************************************************
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync* Header Files *
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync*******************************************************************************/
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync#include "internal/iprt.h"
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync#include <iprt/path.h>
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync#include <iprt/assert.h>
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync#include <iprt/err.h>
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync#include <iprt/string.h>
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsyncRTDECL(int) RTPathJoinEx(char *pszPathDst, size_t cbPathDst,
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync const char *pszPathSrc, size_t cchPathSrcMax,
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync const char *pszAppend, size_t cchAppendMax)
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync{
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync AssertPtr(pszPathDst);
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync AssertPtr(pszPathSrc);
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync AssertPtr(pszAppend);
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync /*
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync * The easy way: Copy the path into the buffer and call RTPathAppend.
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync */
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync size_t cchPathSrc = RTStrNLen(pszPathSrc, cchPathSrcMax);
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync if (cchPathSrc >= cbPathDst)
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync return VERR_BUFFER_OVERFLOW;
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync memcpy(pszPathDst, pszPathSrc, cchPathSrc);
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync pszPathDst[cchPathSrc] = '\0';
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync return RTPathAppendEx(pszPathDst, cbPathDst, pszAppend, cchAppendMax);
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync}
c9a2ef54a0b1991dcd349bf214a622de1356fca3vboxsync