]> pd.if.org Git - zos/blob - klib/strncpy.c
klib and makefile
[zos] / klib / strncpy.c
1 #include <string.h>
2
3 char *strncpy(char *s1, const char *s2, size_t n) {
4         char * rc = s1;
5         while ( (n > 0) && (*s1++ = *s2++) ) {
6                 /* Cannot do "n--" in the conditional as size_t is unsigned and we have
7                  * to check it again for >0 in the next loop below, so we must not risk
8                  * underflow.
9                  */
10                 --n;
11         }
12         /* Checking against 1 as we missed the last --n in the loop above. */
13         while (n-- > 1) {
14                 *s1++ = '\0';
15         }
16         return rc;
17 }