diff options
| author | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2021-12-22 14:21:25 +0000 |
|---|---|---|
| committer | vboxsync <vboxsync@cfe28804-0f27-0410-a406-dd0f0b0b656f> | 2021-12-22 14:21:25 +0000 |
| commit | e1926390ad2e1bafe05b437c1239d702d1d55a2a (patch) | |
| tree | 66d155dd1ab1fa6681aa679331ef9c4ec0084173 /src/VBox/Runtime/common/string/stringalloc.cpp | |
| parent | c187b6f3dfd7515874949ad00cc52ee904016be6 (diff) | |
| download | VirtualBox-svn-e1926390ad2e1bafe05b437c1239d702d1d55a2a.tar.gz | |
IPRT: Added RTStrDupNEx and RTStrDupNExTag.
git-svn-id: https://www.virtualbox.org/svn/vbox/trunk@93057 cfe28804-0f27-0410-a406-dd0f0b0b656f
Diffstat (limited to 'src/VBox/Runtime/common/string/stringalloc.cpp')
| -rw-r--r-- | src/VBox/Runtime/common/string/stringalloc.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/src/VBox/Runtime/common/string/stringalloc.cpp b/src/VBox/Runtime/common/string/stringalloc.cpp index 3d4c8b89501..1beb8808a77 100644 --- a/src/VBox/Runtime/common/string/stringalloc.cpp +++ b/src/VBox/Runtime/common/string/stringalloc.cpp @@ -115,22 +115,24 @@ RTDECL(char *) RTStrDupTag(const char *pszString, const char *pszTag) RT_EXPORT_SYMBOL(RTStrDupTag); -RTDECL(int) RTStrDupExTag(char **ppszString, const char *pszString, const char *pszTag) +RTDECL(int) RTStrDupExTag(char **ppszCopy, const char *pszString, const char *pszTag) { #if defined(__cplusplus) - AssertPtr(ppszString); + AssertPtr(ppszCopy); AssertPtr(pszString); #endif - size_t cch = strlen(pszString) + 1; - char *psz = (char *)RTMemAllocTag(cch, pszTag); - if (psz) + size_t cch = strlen(pszString); + char *pszDst = (char *)RTMemAllocTag(cch + 1, pszTag); + if (pszDst) { - memcpy(psz, pszString, cch); - *ppszString = psz; + memcpy(pszDst, pszString, cch); + pszDst[cch] = '\0'; + *ppszCopy = pszDst; return VINF_SUCCESS; } - return VERR_NO_MEMORY; + *ppszCopy = NULL; + return VERR_NO_STR_MEMORY; } RT_EXPORT_SYMBOL(RTStrDupExTag); @@ -153,6 +155,27 @@ RTDECL(char *) RTStrDupNTag(const char *pszString, size_t cchMax, const char *ps RT_EXPORT_SYMBOL(RTStrDupNTag); +RTDECL(int) RTStrDupNExTag(char **ppszCopy, const char *pszString, size_t cchMax, const char *pszTag) +{ +#if defined(__cplusplus) + AssertPtr(pszString); +#endif + char const *pszEnd = RTStrEnd(pszString, cchMax); + size_t cch = pszEnd ? (uintptr_t)pszEnd - (uintptr_t)pszString : cchMax; + char *pszDst = (char *)RTMemAllocTag(cch + 1, pszTag); + if (pszDst) + { + memcpy(pszDst, pszString, cch); + pszDst[cch] = '\0'; + *ppszCopy = pszDst; + return VINF_SUCCESS; + } + *ppszCopy = NULL; + return VERR_NO_STR_MEMORY; +} +RT_EXPORT_SYMBOL(RTStrDupNExTag); + + RTDECL(int) RTStrAAppendTag(char **ppsz, const char *pszAppend, const char *pszTag) { if (!pszAppend) |
