Root/
Source at commit 1296 created 12 years 9 months ago. By meklort, Add bcopy / sprintf to klibc | |
---|---|
1 | /*␊ |
2 | * strlcpy.c␊ |
3 | */␊ |
4 | ␊ |
5 | #include <string.h>␊ |
6 | ␊ |
7 | size_t strlcpy(char *dst, const char *src, size_t size)␊ |
8 | {␊ |
9 | ␉size_t bytes = 0;␊ |
10 | ␉char *q = dst;␊ |
11 | ␉const char *p = src;␊ |
12 | ␉char ch;␊ |
13 | ␊ |
14 | ␉while ((ch = *p++)) {␊ |
15 | ␉␉if (bytes + 1 < size)␊ |
16 | ␉␉␉*q++ = ch;␊ |
17 | ␊ |
18 | ␉␉bytes++;␊ |
19 | ␉}␊ |
20 | ␊ |
21 | ␉/* If size == 0 there is no space for a final null... */␊ |
22 | ␉if (size)␊ |
23 | ␉␉*q = '\0';␊ |
24 | ␊ |
25 | ␉return bytes;␊ |
26 | }␊ |
27 |