1 // 2 // wcsncpy.cpp 3 // 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // 6 // Defines wcsncpy(), which copies a string from one buffer to another. This 7 // function copies at most 'count' characters. If fewer than 'count' characters 8 // are copied, the rest of the buffer is padded with null characters. 9 // 10 #include <string.h> 11 12 #pragma warning(disable:__WARNING_POSTCONDITION_NULLTERMINATION_VIOLATION) // 26036 13 14 15 #ifdef _M_ARM 16 #pragma function(wcsncpy) 17 #endif 18 19 20 21 extern "C" wchar_t * __cdecl wcsncpy( 22 wchar_t* const destination, 23 wchar_t const* const source, 24 size_t const count 25 ) 26 { 27 size_t remaining = count; 28 29 wchar_t* destination_it = destination; 30 wchar_t const* source_it = source; 31 while (remaining != 0 && (*destination_it++ = *source_it++) != 0) 32 { 33 --remaining; 34 } 35 36 if (remaining != 0) 37 { 38 while (--remaining != 0) 39 { 40 *destination_it++ = L'\0'; 41 } 42 } 43 44 return destination; 45 } 46