strndup.c\string\src - musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/string/strndup.c
blob: 617d27ba9e65ba384fa97433e90b1632015ee998 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
#include <stdlib.h>
#include <string.h>
char *strndup(const char *s, size_t n)
{
	size_t l = strnlen(s, n);
	char *d = malloc(l+1);
	if (!d) return NULL;
	memcpy(d, s, l);
	d[l] = 0;
	return d;
}
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月12日 01:20:47 +0000

AltStyle によって変換されたページ (->オリジナル) /