Changeset 106917 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Nov 10, 2024 2:26:41 AM (5 months ago)
- svn:sync-xref-src-repo-rev:
- 165843
- Location:
- trunk/src/VBox/Runtime/common/string
- Files:
-
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/string/bzero.cpp
r106914 r106917 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - CRT Strings, memset().3 * IPRT - CRT Strings, bzero(). 4 4 */ 5 5 … … 44 44 45 45 /** 46 * Fill a memory block with specific byte.46 * Fill a memory block with zeros. 47 47 * 48 48 * @returns pvDst. 49 * @param pvDst Pointer to the block. 50 * @param ch The filler char. 49 * @param pvDst Pointer to the block. 51 50 * @param cb The size of the block. 52 51 */ 53 #undef memset 54 #ifdef _MSC_VER 55 # if _MSC_VER >= 1400 56 void * __cdecl RT_NOCRT(memset)(__out_bcount_full_opt(_Size) void *pvDst, __in int ch, __in size_t cb) 57 # else 58 void *RT_NOCRT(memset)(void *pvDst, int ch, size_t cb) 59 # endif 60 #else 61 void *RT_NOCRT(memset)(void *pvDst, int ch, size_t cb) 62 #endif 52 #undef bzero 53 void *RT_NOCRT(bzero)(void *pvDst, size_t cb) 63 54 { 64 55 union 65 56 { 66 57 uint8_t *pu8; 67 uint32_t *pu32;58 size_t *puz; 68 59 void *pvDst; 60 uintptr_t uPtr; 69 61 } u; 70 62 u.pvDst = pvDst; 71 63 72 /* 32-bit word moves. */ 73 uint32_t u32 = ch | (ch << 8); 74 u32 |= u32 << 16; 75 size_t c = cb >> 2; 64 /* Align the attack. */ 65 if (cb > sizeof(size_t) * 2 && (u.uPtr % sizeof(size_t))) 66 { 67 size_t c = sizeof(size_t) - (u.uPtr % sizeof(size_t)); 68 cb -= c; 69 while (c-- > 0) 70 *u.pu8++ = 0; 71 } 72 73 /* size_t sized moves. */ 74 size_t c = cb / sizeof(size_t); 76 75 while (c-- > 0) 77 *u.pu 32++ = u32;76 *u.puz++ = 0; 78 77 79 78 /* Remaining byte moves. */ 80 c = cb & 3;79 c = cb % sizeof(size_t); 81 80 while (c-- > 0) 82 *u.pu8++ = (uint8_t)u32;81 *u.pu8++ = 0; 83 82 84 83 return pvDst; 85 84 } 86 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL( memset);85 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(bzero); -
trunk/src/VBox/Runtime/common/string/memmove.cpp
r106914 r106917 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - CRT Strings, mem cpy().3 * IPRT - CRT Strings, memmove(). 4 4 */ 5 5 … … 52 52 */ 53 53 #ifdef IPRT_NO_CRT 54 # undef mem cpy55 void *RT_NOCRT(mem cpy)(void *pvDst, const void *pvSrc, size_t cb)54 # undef memmove 55 void *RT_NOCRT(memmove)(void *pvDst, const void *pvSrc, size_t cb) 56 56 #elif RT_MSC_PREREQ(RT_MSC_VER_VS2005) 57 _CRT_INSECURE_DEPRECATE_MEMORY(mem cpy_s) void * __cdecl58 mem cpy(__out_bcount_full_opt(_Size) void *pvDst, __in_bcount_opt(_Size) const void *pvSrc, __in size_t cb)57 _CRT_INSECURE_DEPRECATE_MEMORY(memmove_s) void * __cdecl 58 memmove(__out_bcount_full_opt(_Size) void *pvDst, __in_bcount_opt(_Size) const void *pvSrc, __in size_t cb) 59 59 #else 60 void *mem cpy(void *pvDst, const void *pvSrc, size_t cb)60 void *memmove(void *pvDst, const void *pvSrc, size_t cb) 61 61 #endif 62 62 { 63 63 union 64 64 { 65 uint8_t *pu8; 66 uint32_t *pu32; 67 void *pv; 65 uint8_t volatile *pu8; 66 size_t volatile *puz; 67 void *pv; 68 uintptr_t uPtr; 68 69 } uTrg; 69 70 uTrg.pv = pvDst; … … 71 72 union 72 73 { 73 uint8_t const *pu8; 74 uint32_t const *pu32; 75 void const *pv; 74 uint8_t const volatile *pu8; 75 size_t const volatile *puz; 76 void const *pv; 77 uintptr_t uPtr; 76 78 } uSrc; 77 79 uSrc.pv = pvSrc; 78 80 79 /* 32-bit word moves. */ 80 size_t c = cb >> 2; 81 while (c-- > 0) 82 *uTrg.pu32++ = *uSrc.pu32++; 81 if (uTrg.uPtr < uSrc.uPtr || uTrg.uPtr >= uSrc.uPtr + cb) 82 { 83 /* 84 * Copy forwards. 85 */ 86 /* size word moves. */ 87 size_t c = cb / sizeof(size_t); 88 while (c-- > 0) 89 *uTrg.puz++ = *uSrc.puz++; 83 90 84 /* Remaining byte moves. */ 85 c = cb & 3; 86 while (c-- > 0) 87 *uTrg.pu8++ = *uSrc.pu8++; 91 /* Remaining byte moves. */ 92 c = cb % sizeof(*uTrg.puz); 93 while (c-- > 0) 94 *uTrg.pu8++ = *uSrc.pu8++; 95 } 96 else if (uTrg.uPtr != uSrc.uPtr) 97 { 98 /* 99 * Copy backwards. 100 */ 101 uTrg.uPtr += cb; 102 uSrc.uPtr += cb; 103 104 /* Byte stuff. */ 105 size_t c = cb % sizeof(*uTrg.puz); 106 while (c-- > 0) 107 *--uTrg.pu8 = *--uSrc.pu8; 108 109 /* size word moves. */ 110 c = cb / sizeof(size_t); 111 while (c-- > 0) 112 *--uTrg.puz = *--uSrc.puz; 113 } 88 114 89 115 return pvDst; 90 116 } 91 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(mem cpy);117 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(memmove); 92 118 -
trunk/src/VBox/Runtime/common/string/strcmp.cpp
r106914 r106917 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - CRT Strings, strc py().3 * IPRT - CRT Strings, strcmp(). 4 4 */ 5 5 … … 44 44 45 45 /** 46 * Co py a string46 * Compares two strings. 47 47 * 48 * @returns Pointer to destination string49 * @param psz Dst Will contain a copy of pszSrc.50 * @param psz Src Zero terminated string.48 * @returns -1, 0 or 1. 49 * @param psz1 Left side string. 50 * @param psz2 Right side stirng. 51 51 */ 52 52 #ifdef IPRT_NO_CRT 53 # undef strc py54 char *RT_NOCRT(strcpy)(char *pszDst, const char *pszSrc)53 # undef strcmp 54 int RT_NOCRT(strcmp)(const char *psz1, const char *psz2) 55 55 #else 56 char *strcpy(char *pszDst, const char *pszSrc)56 int strcmp(const char *psz1, const char *psz2) 57 57 #endif 58 58 { 59 char * const pszRet = pszDst; 60 while ((*pszDst = *pszSrc++) != '\0') 61 pszDst++; 59 for (;;) 60 { 61 char const ch1 = *psz1++; 62 char const ch2 = *psz2++; 63 if (ch1 == ch2) 64 { 65 if (ch1 != 0) 66 { /* likely*/ } 67 else 68 return 0; 69 } 70 else 71 return ch1 < ch2 ? -1 : 1; 72 } 73 } 74 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strcmp); 62 75 63 return pszRet;64 }65 RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(strcpy);66 -
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.