summaryrefslogtreecommitdiff
path: root/cmd-line-utils/libedit/strlcpy.c
blob: 74317d99cd2b70d95012375ad791709950e1562f (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
#include <string.h>

#ifndef HAVE_STRLCPY
size_t strlcpy(char *dst, const char *src, size_t size)
{
	if(size) {
		strncpy(dst, src, size-1);
		dst[size-1] = '\0';
	} else {
		dst[0] = '\0';
	}
	return strlen(src);
}

size_t strlcat(char *dst, const char *src, size_t size)
{
	int dl = strlen(dst);
	int sz = size-dl-1;
	
	if(sz >= 0) {
		strncat(dst, src, sz);
		dst[sz] = '\0';
	}

	return dl+strlen(src);
}

#endif