#define alignof(typ) ( offsetof(struct { char c; typ t; }, t) )
+extern char pathsep;
+
/*
* Compare functions for pathnames. Returns the relative order of
* the names, like strcmp; also passes back the offset of the
*/
static int trieccmp(unsigned char a, unsigned char b)
{
- a = (a == '\0' ? '\0' : a == '/' ? '\1' : a+1);
- b = (b == '\0' ? '\0' : b == '/' ? '\1' : b+1);
- return a - b;
+ a = (a == '\0' ? '\0' : a == pathsep ? '\1' : a+1);
+ b = (b == '\0' ? '\0' : b == pathsep ? '\1' : b+1);
+ return (int)a - (int)b;
}
static int triencmp(const char *a, size_t alen,
off_t root, indexroot;
int count;
size_t maxpathlen;
+ int pathsep;
};
/* Union only used for computing alignment */
th.root = th.count = 0;
th.indexroot = 0;
th.maxpathlen = 0;
+ th.pathsep = (unsigned char)pathsep;
tb_seek(tb, 0);
tb_write(tb, &th, sizeof(th));
th.root = triebuild_unwind(tb, 0, &th.count);
th.indexroot = 0;
th.maxpathlen = tb->maxpathlen;
+ th.pathsep = (unsigned char)pathsep;
tb_seek(tb, 0);
tb_write(tb, &th, sizeof(th));
return hdr->count;
}
+char trie_pathsep(const void *t)
+{
+ const struct trie_header *hdr = NODE(t, 0, trie_header);
+ return (char)hdr->pathsep;
+}
+
struct triewalk_switch {
const struct trie_switch *sw;
int pos, depth, count;
{
return ((const struct trie_header *)t)->indexroot;
}
+
+void make_successor(char *pathbuf)
+{
+ int len = strlen(pathbuf);
+ if (len > 0 && pathbuf[len-1] == pathsep)
+ len--;
+ pathbuf[len] = '\001';
+ pathbuf[len+1] = '\0';
+}