aboutsummaryrefslogblamecommitdiffstats
path: root/strndup.c
blob: 12c80067288b898f6429439ddbea4cb1682d5d71 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

















                                                         
/* See LICENSE file for copyright and license details. */
#include "libsimple.h"


char *
libsimple_strndup(const char *s, size_t n)
{
	void *ret;
	if (n == SIZE_MAX) {
		errno = ENOMEM;
		return NULL;
	}
	if (!(ret = malloc(n + 1)))
		return NULL;
	memcpy(ret, s, n);
	((char *)ret)[n] = '\0';
	return ret;
}