1 /*** 2 *strncpy.c - copy at most n characters of string 3 * 4 * Copyright (c) Microsoft Corporation. All rights reserved. 5 * 6 *Purpose: 7 * defines strncpy() - copy at most n characters of string 8 * 9 *******************************************************************************/ 10 11 #include <string.h> 12 13 #if defined _M_ARM 14 #pragma function(strncpy) 15 #endif 16 17 /*** 18 *char *strncpy(dest, source, count) - copy at most n characters 19 * 20 *Purpose: 21 * Copies count characters from the source string to the 22 * destination. If count is less than the length of source, 23 * NO NULL CHARACTER is put onto the end of the copied string. 24 * If count is greater than the length of sources, dest is padded 25 * with null characters to length count. 26 * 27 * 28 *Entry: 29 * char *dest - pointer to destination 30 * char *source - source string for copy 31 * unsigned count - max number of characters to copy 32 * 33 *Exit: 34 * returns dest 35 * 36 *Exceptions: 37 * 38 *******************************************************************************/ 39 40 char * __cdecl strncpy ( 41 char * dest, 42 const char * source, 43 size_t count 44 ) 45 { 46 char *start = dest; 47 48 while (count && (*dest++ = *source++) != '\0') /* copy string */ 49 count--; 50 51 if (count) /* pad out with zeroes */ 52 while (--count) 53 *dest++ = '\0'; 54 55 return(start); 56 } 57