diff options
Diffstat (limited to 'contrib/sendmail/libsm/strdup.c')
-rw-r--r-- | contrib/sendmail/libsm/strdup.c | 98 |
1 files changed, 96 insertions, 2 deletions
diff --git a/contrib/sendmail/libsm/strdup.c b/contrib/sendmail/libsm/strdup.c index 64fe5c2..7094275 100644 --- a/contrib/sendmail/libsm/strdup.c +++ b/contrib/sendmail/libsm/strdup.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * Copyright (c) 2000-2001, 2003 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -9,7 +9,7 @@ */ #include <sm/gen.h> -SM_RCSID("@(#)$Id: strdup.c,v 1.13 2001/09/11 04:04:49 gshapiro Exp $") +SM_RCSID("@(#)$Id: strdup.c,v 1.15 2003/10/10 17:56:57 ca Exp $") #include <sm/heap.h> #include <sm/string.h> @@ -70,3 +70,97 @@ sm_strdup(s) (void) sm_strlcpy(d, s, l); return d; } + +#if DO_NOT_USE_STRCPY + +/* +** SM_STRDUP_X -- Duplicate a string +** +** Allocates memory and copies source string into it. +** +** Parameters: +** s -- string to copy. +** +** Returns: +** copy of string, exception if out of memory. +** +** Side Effects: +** allocate memory for new string. +*/ + +char * +sm_strdup_x(s) + const char *s; +{ + size_t l; + char *d; + + l = strlen(s) + 1; + d = sm_malloc_tagged_x(l, "sm_strdup_x", 0, sm_heap_group()); + (void) sm_strlcpy(d, s, l); + return d; +} + +/* +** SM_PSTRDUP_X -- Duplicate a string (using "permanent" memory) +** +** Allocates memory and copies source string into it. +** +** Parameters: +** s -- string to copy. +** +** Returns: +** copy of string, exception if out of memory. +** +** Side Effects: +** allocate memory for new string. +*/ + +char * +sm_pstrdup_x(s) + const char *s; +{ + size_t l; + char *d; + + l = strlen(s) + 1; + d = sm_pmalloc_x(l); + (void) sm_strlcpy(d, s, l); + return d; +} + +/* +** SM_STRDUP_X -- Duplicate a string +** +** Allocates memory and copies source string into it. +** +** Parameters: +** s -- string to copy. +** file -- name of source file +** line -- line in source file +** group -- heap group +** +** Returns: +** copy of string, exception if out of memory. +** +** Side Effects: +** allocate memory for new string. +*/ + +char * +sm_strdup_tagged_x(s, file, line, group) + const char *s; + char *file; + int line, group; +{ + size_t l; + char *d; + + l = strlen(s) + 1; + d = sm_malloc_tagged_x(l, file, line, group); + (void) sm_strlcpy(d, s, l); + return d; +} + +#endif /* DO_NOT_USE_STRCPY */ + |