Changeset 36407 in vbox for trunk/src/VBox/Runtime/common/string
- Timestamp:
- Mar 24, 2011 4:14:57 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 70762
- Location:
- trunk/src/VBox/Runtime/common/string
- Files:
-
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/RTStrCatP.cpp
r36382 r36407 33 33 34 34 35 RTDECL(int) RTStrCat (char *pszDst, size_tcbDst, const char *pszSrc)35 RTDECL(int) RTStrCatP(char **ppszDst, size_t *pcbDst, const char *pszSrc) 36 36 { 37 char *pszDst2 = RTStrEnd(pszDst, cbDst); 38 AssertReturn(pszDst2, VERR_INVALID_PARAMETER); 39 cbDst -= pszDst2 - pszDst; 37 /* 38 * Advance past the current string in the output buffer and turn this into 39 * a copy operation. 40 */ 41 size_t cbDst = *pcbDst; 42 char *pszDst = RTStrEnd(*ppszDst, *pcbDst); 43 AssertReturn(pszDst, VERR_INVALID_PARAMETER); 44 *pcbDst -= pszDst - *ppszDst; 45 *ppszDst = pszDst; 40 46 41 size_t cchSrc = strlen(pszSrc); 42 if (RT_LIKELY(cchSrc < cbDst)) 43 { 44 memcpy(pszDst2, pszSrc, cchSrc + 1); 45 return VINF_SUCCESS; 46 } 47 return RTStrCopyP(ppszDst, pcbDst, pszSrc); 48 } 49 RT_EXPORT_SYMBOL(RTStrCatP); 47 50 48 if (cbDst != 0)49 {50 memcpy(pszDst2, pszSrc, cbDst - 1);51 pszDst2[cbDst - 1] = '\0';52 }53 return VERR_BUFFER_OVERFLOW;54 }55 RT_EXPORT_SYMBOL(RTStrCat);56 -
trunk/src/VBox/Runtime/common/string/RTStrCatPEx.cpp
r36382 r36407 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - RTStrCat Ex3 * IPRT - RTStrCatPEx 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 201 0Oracle Corporation7 * Copyright (C) 2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 34 34 35 RTDECL(int) RTStrCat Ex(char *pszDst, size_tcbDst, const char *pszSrc, size_t cchMaxSrc)35 RTDECL(int) RTStrCatPEx(char **ppszDst, size_t *pcbDst, const char *pszSrc, size_t cchMaxSrc) 36 36 { 37 char *pszDst2 = RTStrEnd(pszDst, cbDst); 38 AssertReturn(pszDst2, VERR_INVALID_PARAMETER); 39 cbDst -= pszDst2 - pszDst; 37 /* 38 * Advance past the current string in the output buffer and turn this into 39 * a copy operation. 40 */ 41 size_t cbDst = *pcbDst; 42 char *pszDst = RTStrEnd(*ppszDst, cbDst); 43 AssertReturn(pszDst, VERR_INVALID_PARAMETER); 44 *pcbDst -= pszDst - *ppszDst; 45 *ppszDst = pszDst; 40 46 41 const char *pszSrcEol = RTStrEnd(pszSrc, cchMaxSrc); 42 size_t cchSrc = pszSrcEol ? (size_t)(pszSrcEol - pszSrc) : cchMaxSrc; 43 if (RT_LIKELY(cchSrc < cbDst)) 44 { 45 memcpy(pszDst2, pszSrc, cchSrc); 46 pszDst2[cchSrc] = '\0'; 47 return VINF_SUCCESS; 48 } 47 return RTStrCopyPEx(ppszDst, pcbDst, pszSrc, cchMaxSrc); 48 } 49 RT_EXPORT_SYMBOL(RTStrCatPEx); 49 50 50 if (cbDst != 0)51 {52 memcpy(pszDst2, pszSrc, cbDst - 1);53 pszDst2[cbDst - 1] = '\0';54 }55 return VERR_BUFFER_OVERFLOW;56 }57 RT_EXPORT_SYMBOL(RTStrCatEx);58 -
trunk/src/VBox/Runtime/common/string/RTStrCopyP.cpp
r36382 r36407 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - RTStrCopy .3 * IPRT - RTStrCopyP. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 34 34 35 RTDECL(int) RTStrCopy (char *pszDst, size_tcbDst, const char *pszSrc)35 RTDECL(int) RTStrCopyP(char **ppszDst, size_t *pcbDst, const char *pszSrc) 36 36 { 37 size_t cchSrc = strlen(pszSrc); 37 size_t const cchSrc = strlen(pszSrc); 38 size_t const cbDst = *pcbDst; 39 char *pszDst = *ppszDst; 38 40 if (RT_LIKELY(cchSrc < cbDst)) 39 41 { 40 42 memcpy(pszDst, pszSrc, cchSrc + 1); 43 *ppszDst = pszDst += cchSrc; 44 *pcbDst -= cchSrc; 41 45 return VINF_SUCCESS; 42 46 } … … 44 48 if (cbDst != 0) 45 49 { 46 memcpy(pszDst, pszSrc, cbDst - 1); 47 pszDst[cbDst - 1] = '\0'; 50 memcpy(*ppszDst, pszSrc, cbDst - 1); 51 *ppszDst = pszDst += cbDst - 1; 52 *pszDst = '\0'; 53 *pcbDst = 1; 48 54 } 49 55 return VERR_BUFFER_OVERFLOW; 50 56 } 51 RT_EXPORT_SYMBOL(RTStrCopy );57 RT_EXPORT_SYMBOL(RTStrCopyP); 52 58 -
trunk/src/VBox/Runtime/common/string/RTStrCopyPEx.cpp
r36382 r36407 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - RTStrCopy Ex.3 * IPRT - RTStrCopyPEx. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2010 Oracle Corporation7 * Copyright (C) 2010-2011 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 33 33 34 34 35 RTDECL(int) RTStrCopy Ex(char *pszDst, size_tcbDst, const char *pszSrc, size_t cchMaxSrc)35 RTDECL(int) RTStrCopyPEx(char **ppszDst, size_t *pcbDst, const char *pszSrc, size_t cchMaxSrc) 36 36 { 37 const char *pszSrcEol = RTStrEnd(pszSrc, cchMaxSrc); 38 size_t cchSrc = pszSrcEol ? (size_t)(pszSrcEol - pszSrc) : cchMaxSrc; 37 const char *pszSrcEol = RTStrEnd(pszSrc, cchMaxSrc); 38 size_t cchSrc = pszSrcEol ? (size_t)(pszSrcEol - pszSrc) : cchMaxSrc; 39 size_t const cbDst = *pcbDst; 40 char *pszDst = *ppszDst; 39 41 if (RT_LIKELY(cchSrc < cbDst)) 40 42 { 41 43 memcpy(pszDst, pszSrc, cchSrc); 42 pszDst[cchSrc] = '\0'; 44 *ppszDst = pszDst += cchSrc; 45 *pszDst = '\0'; 46 *pcbDst -= cchSrc; 43 47 return VINF_SUCCESS; 44 48 } … … 46 50 if (cbDst != 0) 47 51 { 48 memcpy(pszDst, pszSrc, cbDst - 1); 49 pszDst[cbDst - 1] = '\0'; 52 memcpy(*ppszDst, pszSrc, cbDst - 1); 53 *ppszDst = pszDst += cbDst - 1; 54 *pszDst = '\0'; 55 *pcbDst = 1; 50 56 } 51 57 return VERR_BUFFER_OVERFLOW; 52 58 } 53 RT_EXPORT_SYMBOL(RTStrCopy Ex);59 RT_EXPORT_SYMBOL(RTStrCopyPEx); 54 60
Note:
See TracChangeset
for help on using the changeset viewer.