Index: /trunk/include/iprt/string.h
===================================================================
--- /trunk/include/iprt/string.h	(revision 26658)
+++ /trunk/include/iprt/string.h	(revision 26659)
@@ -1012,4 +1012,35 @@
 
 /**
+ * String copy with overflow handling.
+ *
+ * @retval  VINF_SUCCESS on success.
+ * @retval  VERR_BUFFER_OVERFLOW if the destination buffer is too small.  The
+ *          buffer will contain as much of the string as it can hold, fully
+ *          terminated.
+ *
+ * @param   pszDst              The destination buffer.
+ * @param   cbDst               The size of the destination buffer (in bytes).
+ * @param   pszSrc              The source string.  NULL is not OK.
+ */
+RTDECL(int) RTStrCopy(char *pszDst, size_t cbDst, const char *pszSrc);
+
+/**
+ * String copy with overflow handling.
+ *
+ * @retval  VINF_SUCCESS on success.
+ * @retval  VERR_BUFFER_OVERFLOW if the destination buffer is too small.  The
+ *          buffer will contain as much of the string as it can hold, fully
+ *          terminated.
+ *
+ * @param   pszDst              The destination buffer.
+ * @param   cbDst               The size of the destination buffer (in bytes).
+ * @param   pszSrc              The source string.  NULL is not OK.
+ * @param   cchSrcMax           The maximum number of chars (not code points) to
+ *                              copy from the source string, not counting the
+ *                              terminator as usual.
+ */
+RTDECL(int) RTStrCopyEx(char *pszDst, size_t cbDst, const char *pszSrc, size_t cchSrcMax);
+
+/**
  * Performs a case sensitive string compare between two UTF-8 strings.
  *
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 26658)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 26659)
@@ -296,4 +296,6 @@
 	common/string/RTStrCmp.cpp \
 	common/string/RTStrConvertHexBytes.cpp \
+	common/string/RTStrCopy.cpp \
+	common/string/RTStrCopyEx.cpp \
 	common/string/RTStrNCmp.cpp \
 	common/string/RTStrNLen.cpp \
@@ -860,4 +862,6 @@
 	common/path/RTPathStripTrailingSlash.cpp \
 	common/string/RTStrCmp.cpp \
+	common/string/RTStrCopy.cpp \
+	common/string/RTStrCopyEx.cpp \
 	common/string/RTStrNCmp.cpp \
         common/string/RTStrNLen.cpp \
@@ -1287,4 +1291,6 @@
 	common/rand/randparkmiller.cpp \
 	common/string/RTStrCmp.cpp \
+	common/string/RTStrCopy.cpp \
+	common/string/RTStrCopyEx.cpp \
 	common/string/RTStrNCmp.cpp \
 	common/string/RTStrNLen.cpp \
Index: /trunk/src/VBox/Runtime/common/string/RTStrCopy.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/string/RTStrCopy.cpp	(revision 26659)
+++ /trunk/src/VBox/Runtime/common/string/RTStrCopy.cpp	(revision 26659)
@@ -0,0 +1,56 @@
+/* $Id$ */
+/** @file
+ * IPRT - RTStrCopy.
+ */
+
+/*
+ * Copyright (C) 2010 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <iprt/string.h>
+#include "internal/iprt.h"
+
+
+RTDECL(int) RTStrCopy(char *pszDst, size_t cbDst, const char *pszSrc)
+{
+    size_t cchSrc = strlen(pszSrc);
+    if (RT_LIKELY(cchSrc < cbDst))
+    {
+        memcpy(pszDst, pszSrc, cchSrc + 1);
+        return VINF_SUCCESS;
+    }
+
+    if (cbDst != 0)
+    {
+        memcpy(pszDst, pszSrc, cbDst - 1);
+        pszDst[cbDst - 1] = '\0';
+    }
+    return VERR_BUFFER_OVERFLOW;
+}
+RT_EXPORT_SYMBOL(RTStrCopy);
+
Index: /trunk/src/VBox/Runtime/common/string/RTStrCopyEx.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/string/RTStrCopyEx.cpp	(revision 26659)
+++ /trunk/src/VBox/Runtime/common/string/RTStrCopyEx.cpp	(revision 26659)
@@ -0,0 +1,58 @@
+/* $Id$ */
+/** @file
+ * IPRT - RTStrCopy.
+ */
+
+/*
+ * Copyright (C) 2010 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <iprt/string.h>
+#include "internal/iprt.h"
+
+
+RTDECL(int) RTStrCopyEx(char *pszDst, size_t cbDst, const char *pszSrc, size_t cchMaxSrc)
+{
+    const char *pszSrcEol = (const char *)memchr(pszSrc, '\0', cchMaxSrc);
+    size_t      cchSrc    = pszSrcEol ? (size_t)(pszSrcEol - pszSrc) : cchMaxSrc;
+    if (RT_LIKELY(cchSrc < cbDst))
+    {
+        memcpy(pszDst, pszSrc, cchSrc);
+        pszDst[cchSrc] = '\0';
+        return VINF_SUCCESS;
+    }
+
+    if (cbDst != 0)
+    {
+        memcpy(pszDst, pszSrc, cbDst - 1);
+        pszDst[cbDst - 1] = '\0';
+    }
+    return VERR_BUFFER_OVERFLOW;
+}
+RT_EXPORT_SYMBOL(RTStrCopyEx);
+
