+char *ensure_end(const char *str, char c)
+{
+ size_t len = strlen(str);
+ char *result;
+
+ if (len && str[len - 1] == c)
+ return xstrndup(str, len);
+
+ result = xmalloc(len + 2);
+ memcpy(result, str, len);
+ result[len] = '/';
+ result[len + 1] = '\0';
+ return result;
+}
+
+void strbuf_ensure_end(struct strbuf *sb, char c)
+{
+ if (!sb->len || sb->buf[sb->len - 1] != c)
+ strbuf_addch(sb, c);
+}
+