Index: /trunk/include/iprt/string.h
===================================================================
--- /trunk/include/iprt/string.h	(revision 22735)
+++ /trunk/include/iprt/string.h	(revision 22736)
@@ -173,4 +173,14 @@
 
 /**
+ * Allocates a new copy of the given UTF-8 substring.
+ *
+ * @returns Pointer to the allocated UTF-8 substring.
+ * @param   pszString       UTF-8 string to duplicate.
+ * @param   cchMax          The max number of chars to duplicate, not counting
+ *                          the terminator.
+ */
+RTDECL(char *) RTStrDupN(const char *pszString, size_t cchMax);
+
+/**
  * Validates the UTF-8 encoding of the string.
  *
Index: /trunk/src/VBox/Runtime/common/string/string.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/string/string.cpp	(revision 22735)
+++ /trunk/src/VBox/Runtime/common/string/string.cpp	(revision 22736)
@@ -65,5 +65,5 @@
 RTDECL(char *) RTStrDup(const char *pszString)
 {
-    Assert(VALID_PTR(pszString));
+    AssertPtr(pszString);
     size_t cch = strlen(pszString) + 1;
     char *psz = (char *)RTMemAlloc(cch);
@@ -85,6 +85,6 @@
 RTDECL(int)  RTStrDupEx(char **ppszString, const char *pszString)
 {
-    Assert(VALID_PTR(ppszString));
-    Assert(VALID_PTR(pszString));
+    AssertPtr(ppszString);
+    AssertPtr(pszString);
 
     size_t cch = strlen(pszString) + 1;
@@ -100,2 +100,28 @@
 RT_EXPORT_SYMBOL(RTStrDupEx);
 
+
+/**
+ * Allocates a new copy of the given UTF-8 substring.
+ *
+ * @returns Pointer to the allocated UTF-8 substring.
+ * @param   pszString       UTF-8 string to duplicate.
+ * @param   cchMax          The max number of chars to duplicate, not counting
+ *                          the terminator.
+ */
+RTDECL(char *) RTStrDupN(const char *pszString, size_t cchMax)
+{
+    AssertPtr(pszString);
+    char  *pszEnd = (char *)memchr(pszString, '\0', cchMax);
+    size_t cch    = pszEnd ? (uintptr_t)pszEnd - (uintptr_t)pszString : cchMax;
+    char  *pszDst = (char *)RTMemAlloc(cch);
+    if (pszDst)
+    {
+        memcpy(pszDst, pszString, cch);
+        pszDst[cch] = '\0';
+    }
+    return pszDst;
+}
+RT_EXPORT_SYMBOL(RTStrDupN);
+
+
+
