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.
12 SM_RCSID("@(#)$Id: strdup.c,v 1.15 2003/10/10 17:56:57 ca Exp $")
15 #include <sm/string.h>
18 ** SM_STRNDUP_X -- Duplicate a string of a given length
20 ** Allocates memory and copies source string (of given length) into it.
23 ** s -- string to copy.
24 ** n -- length to copy.
27 ** copy of string, raises exception if out of memory.
30 ** allocate memory for new string.
38 char *d
= sm_malloc_x(n
+ 1);
40 (void) memcpy(d
, s
, n
);
46 ** SM_STRDUP -- Duplicate a string
48 ** Allocates memory and copies source string into it.
51 ** s -- string to copy.
54 ** copy of string, NULL if out of memory.
57 ** allocate memory for new string.
68 d
= sm_malloc_tagged(l
, "sm_strdup", 0, sm_heap_group());
70 (void) sm_strlcpy(d
, s
, l
);
77 ** SM_STRDUP_X -- Duplicate a string
79 ** Allocates memory and copies source string into it.
82 ** s -- string to copy.
85 ** copy of string, exception if out of memory.
88 ** allocate memory for new string.
99 d
= sm_malloc_tagged_x(l
, "sm_strdup_x", 0, sm_heap_group());
100 (void) sm_strlcpy(d
, s
, l
);
105 ** SM_PSTRDUP_X -- Duplicate a string (using "permanent" memory)
107 ** Allocates memory and copies source string into it.
110 ** s -- string to copy.
113 ** copy of string, exception if out of memory.
116 ** allocate memory for new string.
128 (void) sm_strlcpy(d
, s
, l
);
133 ** SM_STRDUP_X -- Duplicate a string
135 ** Allocates memory and copies source string into it.
138 ** s -- string to copy.
139 ** file -- name of source file
140 ** line -- line in source file
141 ** group -- heap group
144 ** copy of string, exception if out of memory.
147 ** allocate memory for new string.
151 sm_strdup_tagged_x(s
, file
, line
, group
)
160 d
= sm_malloc_tagged_x(l
, file
, line
, group
);
161 (void) sm_strlcpy(d
, s
, l
);
165 #endif /* DO_NOT_USE_STRCPY */