chiark / gitweb /
[PATCH] klibc: version 1.0.5
[elogind.git] / klibc / klibc / strlcpy.c
1 /*
2  * strlcpy.c
3  */
4
5 #include <string.h>
6 #include <klibc/compiler.h>
7
8 size_t strlcpy(char *dst, const char *src, size_t size)
9 {
10   size_t bytes = 0;
11   char *q = dst;
12   const char *p = src;
13   char ch;
14
15   while ( (ch = *p++) ) {
16     if ( bytes+1 < size )
17       *q++ = ch;
18
19     bytes++;
20   }
21
22   /* If size == 0 there is no space for a final null... */
23   if ( size )
24     *q = '\0';
25
26   return bytes;
27 }
28
29