aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/string.c
blob: 878efebb990bd82c9091a5ba3c209f33421eb230 (plain) (blame)
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
/*
 * Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
 * This file is part of the "cimple" project.
 * For details, see https://github.com/egor-tensin/cimple.
 * Distributed under the MIT License.
 */

#include "string.h"

#include <string.h>

char *stpecpy(char *dst, char *end, const char *src)
{
	if (!dst)
		return NULL;
	if (dst == end)
		return end;

	char *p = memccpy(dst, src, '\0', end - dst);
	if (p)
		return p - 1;

	end[-1] = '\0';
	return end;
}