aboutsummaryrefslogtreecommitdiff
path: root/stecpy-builtin.c
blob: 72f6adcef5cfae899b95c4aa36084059f3f9dd02 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <string.h>

char *
stecpy(char *dst, char *end, const char *src)
{
        if (dst >= end)
                return dst;

	size_t n = strnlen(src, end - dst);

	if (n == end - dst) {
		memcpy(dst, src, n - 1);
		end[-1] = 0;
		return end;
	}

	return memcpy(dst, src, n + 1) + n;
}