summaryrefslogtreecommitdiff
path: root/oslib/strndup.c
blob: 40e92f820d12b1279e35a94739dde78f16746fa6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdlib.h>

#include "strndup.h"

#ifndef CONFIG_HAVE_STRNDUP

char *strndup(const char *s, size_t n)
{
	char *str = malloc(n + 1);

	if (str) {
		strncpy(str, s, n);
		str[n] = '\0';
	}

	return str;
}

#endif