summaryrefslogtreecommitdiff
path: root/com32/lib/strlcat.c
blob: 6111445f0629948c738ecd91b2cd2fe54a86c5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * strlcat.c
 */

#include <string.h>
#include <klibc/compiler.h>

size_t strlcat(char *dst, const char *src, size_t size)
{
  size_t bytes = 0;
  char *q = dst;
  const char *p = src;
  char ch;

  while ( bytes < size && *q ) {
    q++;
    bytes++;
  }

  while ( (ch = *p++) ) {
    if ( bytes < size )
      *q++ = ch;

    bytes++;
  }

  *q = '\0';
  return bytes;
}