From: Ken Raeburn Date: Wed, 19 Jun 2002 21:02:37 +0000 (+0000) Subject: use strdup X-Git-Tag: krb5-1.3-alpha1~678 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4f20424df747fc1aa060ff55b00265d517526756;p=krb5.git use strdup git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@14541 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index 53c8641ce..d9f30d867 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,9 @@ +2002-06-19 Ken Raeburn + + * configure.in: Look for strdup. + * prof_tree.c (profile_create_node): Use strdup. + (strdup, MYstrdup): Define it if the OS doesn't provide it. + 2002-06-04 Ken Raeburn * prof_get.c (profile_get_integer): Set errno to 0 before strtol diff --git a/src/util/profile/configure.in b/src/util/profile/configure.in index 390f1427d..acb6010fe 100644 --- a/src/util/profile/configure.in +++ b/src/util/profile/configure.in @@ -5,7 +5,7 @@ AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_HEADERS(unistd.h stdlib.h) -AC_CHECK_FUNCS(stat access) +AC_CHECK_FUNCS(stat access strdup) AC_PROG_AWK KRB5_BUILD_LIBOBJS KRB5_BUILD_PROGRAM diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c index 5c4e998bf..be76db328 100644 --- a/src/util/profile/prof_tree.c +++ b/src/util/profile/prof_tree.c @@ -67,6 +67,19 @@ void profile_free_node(node) free(node); } +#ifndef HAVE_STRDUP +#undef strdup +#define strdup MYstrdup +static char *MYstrdup (const char *s) +{ + size_t sz = strlen(s) + 1; + char *p = malloc(sz); + if (p != 0) + memcpy(p, s, sz); + return p; +} +#endif + /* * Create a node */ @@ -80,19 +93,17 @@ errcode_t profile_create_node(name, value, ret_node) if (!new) return ENOMEM; memset(new, 0, sizeof(struct profile_node)); - new->name = malloc(strlen(name)+1); + new->name = strdup(name); if (new->name == 0) { - profile_free_node(new); - return ENOMEM; + profile_free_node(new); + return ENOMEM; } - strcpy(new->name, name); if (value) { - new->value = malloc(strlen(value)+1); + new->value = strdup(value); if (new->value == 0) { - profile_free_node(new); - return ENOMEM; + profile_free_node(new); + return ENOMEM; } - strcpy(new->value, value); } new->magic = PROF_MAGIC_NODE;