9b06e960a44811075e905188ad6465c5ad813f28vboxsync/* $Id$ */
9b06e960a44811075e905188ad6465c5ad813f28vboxsync/** @file
43b5dc1de36c0382122e939b0795bc9975cabd0cvboxsync * IPRT - RTStrCopyEx.
9b06e960a44811075e905188ad6465c5ad813f28vboxsync */
9b06e960a44811075e905188ad6465c5ad813f28vboxsync
9b06e960a44811075e905188ad6465c5ad813f28vboxsync/*
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2010 Oracle Corporation
9b06e960a44811075e905188ad6465c5ad813f28vboxsync *
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * available from http://www.virtualbox.org. This file is free software;
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * General Public License (GPL) as published by the Free Software
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9b06e960a44811075e905188ad6465c5ad813f28vboxsync *
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * The contents of this file may alternatively be used under the terms
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * of the Common Development and Distribution License Version 1.0
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * VirtualBox OSE distribution, in which case the provisions of the
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * CDDL are applicable instead of those of the GPL.
9b06e960a44811075e905188ad6465c5ad813f28vboxsync *
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * You may elect to license modified versions of this file under the
9b06e960a44811075e905188ad6465c5ad813f28vboxsync * terms and conditions of either the GPL or the CDDL or both.
9b06e960a44811075e905188ad6465c5ad813f28vboxsync */
9b06e960a44811075e905188ad6465c5ad813f28vboxsync
9b06e960a44811075e905188ad6465c5ad813f28vboxsync
9b06e960a44811075e905188ad6465c5ad813f28vboxsync/*******************************************************************************
9b06e960a44811075e905188ad6465c5ad813f28vboxsync* Header Files *
9b06e960a44811075e905188ad6465c5ad813f28vboxsync*******************************************************************************/
9b06e960a44811075e905188ad6465c5ad813f28vboxsync#include <iprt/string.h>
9b06e960a44811075e905188ad6465c5ad813f28vboxsync#include "internal/iprt.h"
9b06e960a44811075e905188ad6465c5ad813f28vboxsync
9b06e960a44811075e905188ad6465c5ad813f28vboxsync
9b06e960a44811075e905188ad6465c5ad813f28vboxsyncRTDECL(int) RTStrCopyEx(char *pszDst, size_t cbDst, const char *pszSrc, size_t cchMaxSrc)
9b06e960a44811075e905188ad6465c5ad813f28vboxsync{
e86538a7bc028e823f16f8982e90f0c7ef5d4ecevboxsync const char *pszSrcEol = RTStrEnd(pszSrc, cchMaxSrc);
9b06e960a44811075e905188ad6465c5ad813f28vboxsync size_t cchSrc = pszSrcEol ? (size_t)(pszSrcEol - pszSrc) : cchMaxSrc;
9b06e960a44811075e905188ad6465c5ad813f28vboxsync if (RT_LIKELY(cchSrc < cbDst))
9b06e960a44811075e905188ad6465c5ad813f28vboxsync {
9b06e960a44811075e905188ad6465c5ad813f28vboxsync memcpy(pszDst, pszSrc, cchSrc);
9b06e960a44811075e905188ad6465c5ad813f28vboxsync pszDst[cchSrc] = '\0';
9b06e960a44811075e905188ad6465c5ad813f28vboxsync return VINF_SUCCESS;
9b06e960a44811075e905188ad6465c5ad813f28vboxsync }
9b06e960a44811075e905188ad6465c5ad813f28vboxsync
9b06e960a44811075e905188ad6465c5ad813f28vboxsync if (cbDst != 0)
9b06e960a44811075e905188ad6465c5ad813f28vboxsync {
9b06e960a44811075e905188ad6465c5ad813f28vboxsync memcpy(pszDst, pszSrc, cbDst - 1);
9b06e960a44811075e905188ad6465c5ad813f28vboxsync pszDst[cbDst - 1] = '\0';
9b06e960a44811075e905188ad6465c5ad813f28vboxsync }
9b06e960a44811075e905188ad6465c5ad813f28vboxsync return VERR_BUFFER_OVERFLOW;
9b06e960a44811075e905188ad6465c5ad813f28vboxsync}
9b06e960a44811075e905188ad6465c5ad813f28vboxsyncRT_EXPORT_SYMBOL(RTStrCopyEx);
9b06e960a44811075e905188ad6465c5ad813f28vboxsync