summaryrefslogtreecommitdiff
path: root/klibc/klibc/strncpy.c
blob: a8fe45fcbb588bccb28c9fadaf821adef5e0df10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * strncpy.c
 *
 * strncpy()
 */

#include <string.h>

char *strncpy(char *dst, const char *src, size_t n)
{
  char *q = dst;
  const char *p = src;
  char ch;

  while ( n-- ) {
    *q++ = ch = *p++;
    if ( !ch )
      break;
  }

  return dst;
}