Root/
Source at commit 1314 created 12 years 10 months ago. By meklort, Temp hacks for xml parser | |
---|---|
1 | /*␊ |
2 | * strncpy.c␊ |
3 | */␊ |
4 | ␊ |
5 | #include <string.h>␊ |
6 | ␊ |
7 | char *strncpy(char *dst, const char *src, size_t n)␊ |
8 | {␊ |
9 | ␉char *q = dst;␊ |
10 | ␉const char *p = src;␊ |
11 | ␉char ch;␊ |
12 | ␊ |
13 | ␉while (n) {␊ |
14 | ␉␉n--;␊ |
15 | ␉␉*q++ = ch = *p++;␊ |
16 | ␉␉if (!ch)␊ |
17 | ␉␉␉break;␊ |
18 | ␉}␊ |
19 | ␊ |
20 | ␉/* The specs say strncpy() fills the entire buffer with NUL. Sigh. */␊ |
21 | ␉memset(q, 0, n);␊ |
22 | ␊ |
23 | ␉return dst;␊ |
24 | }␊ |
25 |