2 * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
11 #pragma ident "%Z%%M% %I% %E% SMI"
14 SM_RCSID("@(#)$Id: strdup.c,v 1.15 2003/10/10 17:56:57 ca Exp $")
17 #include <sm/string.h>
20 ** SM_STRNDUP_X -- Duplicate a string of a given length
22 ** Allocates memory and copies source string (of given length) into it.
25 ** s -- string to copy.
26 ** n -- length to copy.
29 ** copy of string, raises exception if out of memory.
32 ** allocate memory for new string.
40 char *d
= sm_malloc_x(n
+ 1);
42 (void) memcpy(d
, s
, n
);
48 ** SM_STRDUP -- Duplicate a string
50 ** Allocates memory and copies source string into it.
53 ** s -- string to copy.
56 ** copy of string, NULL if out of memory.
59 ** allocate memory for new string.
70 d
= sm_malloc_tagged(l
, "sm_strdup", 0, sm_heap_group());
72 (void) sm_strlcpy(d
, s
, l
);
79 ** SM_STRDUP_X -- Duplicate a string
81 ** Allocates memory and copies source string into it.
84 ** s -- string to copy.
87 ** copy of string, exception if out of memory.
90 ** allocate memory for new string.
101 d
= sm_malloc_tagged_x(l
, "sm_strdup_x", 0, sm_heap_group());
102 (void) sm_strlcpy(d
, s
, l
);
107 ** SM_PSTRDUP_X -- Duplicate a string (using "permanent" memory)
109 ** Allocates memory and copies source string into it.
112 ** s -- string to copy.
115 ** copy of string, exception if out of memory.
118 ** allocate memory for new string.
130 (void) sm_strlcpy(d
, s
, l
);
135 ** SM_STRDUP_X -- Duplicate a string
137 ** Allocates memory and copies source string into it.
140 ** s -- string to copy.
141 ** file -- name of source file
142 ** line -- line in source file
143 ** group -- heap group
146 ** copy of string, exception if out of memory.
149 ** allocate memory for new string.
153 sm_strdup_tagged_x(s
, file
, line
, group
)
162 d
= sm_malloc_tagged_x(l
, file
, line
, group
);
163 (void) sm_strlcpy(d
, s
, l
);
167 #endif /* DO_NOT_USE_STRCPY */