diff options
Diffstat (limited to 'private/crt32/string/strncpy.c')
-rw-r--r-- | private/crt32/string/strncpy.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/private/crt32/string/strncpy.c b/private/crt32/string/strncpy.c new file mode 100644 index 000000000..96b75a155 --- /dev/null +++ b/private/crt32/string/strncpy.c @@ -0,0 +1,59 @@ +/*** +*strncpy.c - copy at most n characters of string +* +* Copyright (c) 1985-1991, Microsoft Corporation. All rights reserved. +* +*Purpose: +* defines strncpy() - copy at most n characters of string +* +*Revision History: +* 05-31-89 JCR C version created. +* 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed +* copyright. +* 10-02-90 GJF New-style function declarator. +* +*******************************************************************************/ + +#include <cruntime.h> +#include <string.h> + +/*** +*char *strncpy(dest, source, count) - copy at most n characters +* +*Purpose: +* Copies count characters from the source string to the +* destination. If count is less than the length of source, +* NO NULL CHARACTER is put onto the end of the copied string. +* If count is greater than the length of sources, dest is padded +* with null characters to length count. +* +* +*Entry: +* char *dest - pointer to destination +* char *source - source string for copy +* unsigned count - max number of characters to copy +* +*Exit: +* returns dest +* +*Exceptions: +* +*******************************************************************************/ + +char * _CALLTYPE1 strncpy ( + char * dest, + const char * source, + size_t count + ) +{ + char *start = dest; + + while (count && (*dest++ = *source++)) /* copy string */ + count--; + + if (count) /* pad out with zeroes */ + while (--count) + *dest++ = '\0'; + + return(start); +} |