free (name->buf);
name->buf = NULL;
}
-
+
free(name);
}
-TR_NAME *tr_new_name (char *name)
+TR_NAME *tr_new_name (const char *name)
{
TR_NAME *new;
- if (new = malloc(sizeof(TR_NAME))) {
+ if (new = malloc(sizeof(TR_NAME))) {
new->len = strlen(name);
if (new->buf = malloc((new->len)+1)) {
strcpy(new->buf, name);
return new;
}
-TR_NAME *tr_dup_name (TR_NAME *from)
+TR_NAME *tr_dup_name (TR_NAME *from)
{
TR_NAME *to;
- if (to = malloc(sizeof(TR_NAME))) {
+ if (!from) {
+ return NULL;
+ }
+
+ if (NULL != (to = malloc(sizeof(TR_NAME)))) {
to->len = from->len;
- if (to->buf = malloc(to->len+1)) {
+ if (NULL != (to->buf = malloc(to->len+1))) {
strncpy(to->buf, from->buf, from->len);
to->buf[to->len] = 0; /* NULL terminate for debugging printf()s */
}
}
-
return to;
}
{
if (one->len != two->len)
return 1;
- else
- /* TBD -- should really do a length-based comparison */
- return strcmp(one->buf, two->buf);
+ else {
+ /* lengths equal */
+ return strncmp(one->buf, two->buf, one->len);
+ }
}
void tr_name_strlcat(char *dest, const TR_NAME *src, size_t len)
return s;
}
-
+