Changeset 106917 in vbox for trunk/src/VBox/Runtime/common/string/strncpy.cpp
- Timestamp:
- Nov 10, 2024 2:26:41 AM (3 months ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/strncpy.cpp
r106914 r106917 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - CRT Strings, str cpy().3 * IPRT - CRT Strings, strncpy(). 4 4 */ 5 5 … … 49 49 * @param pszDst Will contain a copy of pszSrc. 50 50 * @param pszSrc Zero terminated string. 51 * @param cbDst Size of the destination buffer. 51 52 */ 52 53 #ifdef IPRT_NO_CRT 53 # undef str cpy54 char *RT_NOCRT(str cpy)(char *pszDst, const char *pszSrc)54 # undef strncpy 55 char *RT_NOCRT(strncpy)(char *pszDst, const char *pszSrc, size_t cbDst) 55 56 #else 56 char *str cpy(char *pszDst, const char *pszSrc)57 char *strncpy(char *pszDst, const char *pszSrc, size_t cbDst) 57 58 #endif 58 59 { 59 char * const pszRet = pszDst; 60 while ((*pszDst = *pszSrc++) != '\0') 61 pszDst++; 60 size_t off = 0; 61 while (off < cbDst) 62 { 63 char const ch = *pszSrc; 64 pszDst[off++] = ch; 65 if (ch) 66 { /* likely */ } 67 else 68 { 69 /* (this zeroing is not very efficient) */ 70 while (off < cbDst) 71 pszDst[off++] = '\0'; 72 break; 73 } 74 } 62 75 63 return psz Ret;76 return pszDst; 64 77 } 65 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(str cpy);78 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strncpy); 66 79
Note:
See TracChangeset
for help on using the changeset viewer.