summaryrefslogtreecommitdiffstats
path: root/Python/strdup.c
blob: 5198e25e087734ed66f121def81af950ad61ea1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* strdup() replacement (from stdwin, if you must know) */

#include "config.h"
#include <string.h>

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
extern ANY *malloc Py_PROTO((size_t));
#endif

char *
strdup(str)
	const char *str;
{
	if (str != NULL) {
		register char *copy = malloc(strlen(str) + 1);
		if (copy != NULL)
			return strcpy(copy, str);
	}
	return NULL;
}