+ const char *wc_post=NULL;
+ size_t wc_len = 0;
+
+ if ((!str) || (!wc_str))
+ return 0;
+
+ wc_len = (size_t) wc_str->len;
+ if (wc_len == 0)
+ return 0;
+
+ if ('*' == wc_str->buf[0]) {
+ /* Wildcard, so the actual compare will start at the second character of wc_str */
+ wc_post = wc_str->buf + 1;
+ wc_len--;
+ } else if (str->len == wc_len) {
+ /* No wildcard, but the strings are the same length so may match.
+ * Compare the full strings. */
+ wc_post=wc_str->buf;
+ wc_len = (size_t) wc_str->len;
+ } else {
+ /* No wildcard and strings are different length, so no match */
+ return 0;
+ }
+
+ /* A match is not possible if the fixed part of the wildcard string is longer than
+ * the string to match it against. */
+ if (wc_len > str->len)
+ return 0;
+
+ /* Now we compare the last wc_len characters of str against wc_post */
+ return (0 == strncmp(str->buf + str->len - wc_len, wc_post, wc_len));
+}
+
+void tr_name_strlcat(char *dest, const TR_NAME *src, size_t len)
+{
+ size_t used_len;
+ if (src->len >= len)
+ used_len = len-1;
+ else
+ used_len = (size_t) src->len;
+ if (used_len > 0)
+ strncat(dest, src->buf, used_len);
+ else dest[0] = '\0';
+}
+
+
+char * tr_name_strdup(const TR_NAME *src)
+{
+ char *s = calloc(1 + (size_t) src->len, 1);
+ if (s) {
+ memcpy(s, src->buf, (size_t) src->len);
+ s[src->len] = '\0';
+ }
+ return s;
+}
+
+json_t *tr_name_to_json_string(const TR_NAME *src)
+{
+ char *s=tr_name_strdup(src);
+ json_t *js=json_string(s);
+ if (s!=NULL)
+ free(s);
+ return js;
+}
+
+TR_NAME *tr_name_cat(const TR_NAME *n1, const TR_NAME *n2)
+{
+ char *s=malloc((size_t) n1->len + (size_t) n2->len + 1);
+ TR_NAME *name=NULL;
+
+ if (s==NULL)
+ return NULL;
+ *s=0;
+ strncat(s, n1->buf, (size_t) n1->len);
+ strncat(s, n2->buf, (size_t) n2->len);
+ name=tr_new_name(s);
+ free(s);
+ return name;