about summary refs log tree commit diff
path: root/stecpe.c
blob: b943843d378403af9193ad769970388bf8eb5687 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stddef.h>
#include <string.h>

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

	ptrdiff_t l = end - dst - 1;
	size_t t = 1;
	if (srcend - src < l) {
		l = srcend - src;
		t = 0;
	}

	memcpy(dst, src, l);
	dst[l] = 0;

	return dst + l + t;
}