summaryrefslogtreecommitdiffstats
path: root/subsurface-core/strndup.h
blob: 84e18b60fabee362f64301c6bb9685ba581919a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef STRNDUP_H
#define STRNDUP_H
#if __WIN32__
static char *strndup (const char *s, size_t n)
{
	char *cpy;
	size_t len = strlen(s);
	if (n < len)
		len = n;
	if ((cpy = malloc(len + 1)) !=
	    NULL) {
		cpy[len] =
				'\0';
		memcpy(cpy,
		       s,
		       len);
	}
	return cpy;
}
#endif
#endif /* STRNDUP_H */