- Timestamp:
- Mar 24, 2011 4:14:57 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r36267 r36407 1123 1123 #define RTStrCat RT_MANGLER(RTStrCat) 1124 1124 #define RTStrCatEx RT_MANGLER(RTStrCatEx) 1125 #define RTStrCatP RT_MANGLER(RTStrCatP) 1126 #define RTStrCatPEx RT_MANGLER(RTStrCatPEx) 1125 1127 #define RTStrCmp RT_MANGLER(RTStrCmp) 1126 1128 #define RTStrConvertHexBytes RT_MANGLER(RTStrConvertHexBytes) 1127 1129 #define RTStrCopy RT_MANGLER(RTStrCopy) 1128 1130 #define RTStrCopyEx RT_MANGLER(RTStrCopyEx) 1131 #define RTStrCopyP RT_MANGLER(RTStrCopyP) 1132 #define RTStrCopyPEx RT_MANGLER(RTStrCopyPEx) 1129 1133 #define RTStrCurrentCPToUtf8Tag RT_MANGLER(RTStrCurrentCPToUtf8Tag) 1130 1134 #define RTStrDupExTag RT_MANGLER(RTStrDupExTag) -
trunk/include/iprt/string.h
r35585 r36407 2151 2151 2152 2152 /** 2153 * String copy with overflow handling and buffer advancing. 2154 * 2155 * @retval VINF_SUCCESS on success. 2156 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The 2157 * buffer will contain as much of the string as it can hold, fully 2158 * terminated. 2159 * 2160 * @param ppszDst Pointer to the destination buffer pointer. 2161 * This will be advanced to the end of the copied 2162 * bytes (points at the terminator). This is also 2163 * updated on overflow. 2164 * @param pcbDst Pointer to the destination buffer size 2165 * variable. This will be updated in accord with 2166 * the buffer pointer. 2167 * @param pszSrc The source string. NULL is not OK. 2168 */ 2169 RTDECL(int) RTStrCopyP(char **ppszDst, size_t *pcbDst, const char *pszSrc); 2170 2171 /** 2172 * String copy with overflow handling. 2173 * 2174 * @retval VINF_SUCCESS on success. 2175 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The 2176 * buffer will contain as much of the string as it can hold, fully 2177 * terminated. 2178 * 2179 * @param ppszDst Pointer to the destination buffer pointer. 2180 * This will be advanced to the end of the copied 2181 * bytes (points at the terminator). This is also 2182 * updated on overflow. 2183 * @param pcbDst Pointer to the destination buffer size 2184 * variable. This will be updated in accord with 2185 * the buffer pointer. 2186 * @param pszSrc The source string. NULL is not OK. 2187 * @param cchSrcMax The maximum number of chars (not code points) to 2188 * copy from the source string, not counting the 2189 * terminator as usual. 2190 */ 2191 RTDECL(int) RTStrCopyPEx(char **ppszDst, size_t *pcbDst, const char *pszSrc, size_t cchSrcMax); 2192 2193 /** 2153 2194 * String concatenation with overflow handling. 2154 2195 * … … 2180 2221 */ 2181 2222 RTDECL(int) RTStrCatEx(char *pszDst, size_t cbDst, const char *pszSrc, size_t cchSrcMax); 2223 2224 /** 2225 * String concatenation with overflow handling. 2226 * 2227 * @retval VINF_SUCCESS on success. 2228 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The 2229 * buffer will contain as much of the string as it can hold, fully 2230 * terminated. 2231 * 2232 * @param ppszDst Pointer to the destination buffer pointer. 2233 * This will be advanced to the end of the copied 2234 * bytes (points at the terminator). This is also 2235 * updated on overflow. 2236 * @param pcbDst Pointer to the destination buffer size 2237 * variable. This will be updated in accord with 2238 * the buffer pointer. 2239 * @param pszSrc The source string. NULL is not OK. 2240 */ 2241 RTDECL(int) RTStrCatP(char **ppszDst, size_t *pcbDst, const char *pszSrc); 2242 2243 /** 2244 * String concatenation with overflow handling and buffer advancing. 2245 * 2246 * @retval VINF_SUCCESS on success. 2247 * @retval VERR_BUFFER_OVERFLOW if the destination buffer is too small. The 2248 * buffer will contain as much of the string as it can hold, fully 2249 * terminated. 2250 * 2251 * @param ppszDst Pointer to the destination buffer pointer. 2252 * This will be advanced to the end of the copied 2253 * bytes (points at the terminator). This is also 2254 * updated on overflow. 2255 * @param pcbDst Pointer to the destination buffer size 2256 * variable. This will be updated in accord with 2257 * the buffer pointer. 2258 * @param pszSrc The source string. NULL is not OK. 2259 * @param cchSrcMax The maximum number of chars (not code points) to 2260 * copy from the source string, not counting the 2261 * terminator as usual. 2262 */ 2263 RTDECL(int) RTStrCatPEx(char **ppszDst, size_t *pcbDst, const char *pszSrc, size_t cchSrcMax); 2182 2264 2183 2265 /** -
trunk/src/VBox/Runtime/Makefile.kmk
r35857 r36407 5 5 6 6 # 7 # Copyright (C) 2006-201 0Oracle Corporation7 # Copyright (C) 2006-2011 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 354 354 common/string/RTStrCat.cpp \ 355 355 common/string/RTStrCatEx.cpp \ 356 common/string/RTStrCatP.cpp \ 357 common/string/RTStrCatPEx.cpp \ 356 358 common/string/RTStrCmp.cpp \ 357 359 common/string/RTStrConvertHexBytes.cpp \ 358 360 common/string/RTStrCopy.cpp \ 359 361 common/string/RTStrCopyEx.cpp \ 362 common/string/RTStrCopyP.cpp \ 363 common/string/RTStrCopyPEx.cpp \ 360 364 common/string/RTStrNCmp.cpp \ 361 365 common/string/RTStrNLen.cpp \ … … 1073 1077 common/string/RTStrCat.cpp \ 1074 1078 common/string/RTStrCatEx.cpp \ 1079 common/string/RTStrCatP.cpp \ 1080 common/string/RTStrCatPEx.cpp \ 1075 1081 common/string/RTStrCmp.cpp \ 1076 1082 common/string/RTStrCopy.cpp \ 1077 1083 common/string/RTStrCopyEx.cpp \ 1084 common/string/RTStrCopyP.cpp \ 1085 common/string/RTStrCopyPEx.cpp \ 1078 1086 common/string/RTStrNCmp.cpp \ 1079 1087 common/string/RTStrNLen.cpp \ … … 1418 1426 common/string/RTStrCat.cpp \ 1419 1427 common/string/RTStrCatEx.cpp \ 1428 common/string/RTStrCatP.cpp \ 1429 common/string/RTStrCatPEx.cpp \ 1420 1430 common/string/RTStrCopy.cpp \ 1421 1431 common/string/RTStrCopyEx.cpp \ 1432 common/string/RTStrCopyP.cpp \ 1433 common/string/RTStrCopyPEx.cpp \ 1422 1434 common/string/RTStrNLen.cpp \ 1423 1435 common/string/RTStrNLenEx.cpp \ … … 1556 1568 common/string/RTStrCat.cpp \ 1557 1569 common/string/RTStrCatEx.cpp \ 1570 common/string/RTStrCatP.cpp \ 1571 common/string/RTStrCatPEx.cpp \ 1558 1572 common/string/RTStrCmp.cpp \ 1559 1573 common/string/RTStrCopy.cpp \ 1560 1574 common/string/RTStrCopyEx.cpp \ 1575 common/string/RTStrCopyP.cpp \ 1576 common/string/RTStrCopyPEx.cpp \ 1561 1577 common/string/RTStrNCmp.cpp \ 1562 1578 common/string/RTStrNLen.cpp \ -
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.