disable debug.
[AROS.git] / compiler / alib / strdup.c
blob00926630f9dd2c619c1b26fb07cf32a6b05a0586
1 /*
2 Copyright © 2002-2016, The AROS Development Team. All rights reserved.
3 $Id$
5 AllocVec-based string duplication.
6 */
8 #include "alib_intern.h"
9 #include <exec/memory.h>
11 /*****************************************************************************
13 NAME */
14 #define NO_INLINE_STDARG /* turn off inline def */
15 #include <proto/exec.h>
17 STRPTR StrDup (
19 /* SYNOPSIS */
20 CONST_STRPTR str)
22 /* FUNCTION
23 This function allocates enough space, and copies the given string
24 into it.
26 INPUTS
27 str - the string to duplicate
29 RESULT
30 A string copy of the original string (possibly of zero length) or
31 NULL if passed a NULL pointer.
33 NOTES
34 This functions allocates the new string memory with AllocVec().
35 Don't forget to call FreeVec() when you're done with it.
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 exec.library/AllocVec(), exec.library/FreeVec(), exec.library/CopyMem()
44 INTERNALS
46 *****************************************************************************/
48 STRPTR dup;
49 ULONG len;
51 if (str == NULL) return NULL;
53 len = STRLEN(str);
54 dup = AllocVec(len + 1, MEMF_PUBLIC);
55 if (dup != NULL) CopyMem(str, dup, len + 1);
57 return dup;
59 } /* StrDup */