1 /*
2 * strdup.c -- version of strdup for systems without one
3 *
4 * Copyright (C)1999-2006 Mark Simpson <damned@theworld.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you can either send email to this
18 * program's maintainer or write to: The Free Software Foundation,
19 * Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
20 *
21 */
22 #ifdef HAVE_CONFIG_H
23 # include "config.h"
24 #endif /* HAVE_CONFIG_H */
25
26 #if !HAVE_STRDUP
27 #include <assert.h>
28 #include <stdio.h>
29
30 #if STDC_HEADERS
31 # include <stdlib.h>
32 #else
33 extern size_t strlen (const char *);
34
35 # if !HAVE_MEMMOVE
36 # define memmove(d,s,n) bcopy((s),(d),(n));
37 # else
38 extern void* memmove (void *, const void *, size_t);
39 # endif
40 #endif
41
42 char *
strdup(const char * str)43 strdup (const char *str)
44 {
45 size_t len = strlen(str);
46 char *out = malloc ((len+1) * sizeof (char));
47 memmove (out, str, (len + 1));
48 return out;
49 }
50 #endif /* !HAVE_STRDUP */
51
52