+2002-06-19 Ken Raeburn <raeburn@mit.edu>
+
+ * 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 <raeburn@mit.edu>
* prof_get.c (profile_get_integer): Set errno to 0 before strtol
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
*/
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;