summaryrefslogtreecommitdiff
path: root/corebinutils/ed/compat.c
blob: d034179584688d3e12f8d80c2b9693b4fc588801 (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
/*-
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "compat.h"

size_t
ed_strlcpy(char *dst, const char *src, size_t dstsize)
{
	const char *s;
	size_t srclen;

	s = src;
	while (*s != '\0')
		s++;
	srclen = (size_t)(s - src);

	if (dstsize != 0) {
		size_t copylen;
		size_t i;

		copylen = srclen;
		if (copylen >= dstsize)
			copylen = dstsize - 1;
		for (i = 0; i < copylen; i++)
			dst[i] = src[i];
		dst[copylen] = '\0';
	}

	return srclen;
}