1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-22 19:39:54 +02:00

b2/util.c: new function unique_n for strings limited by length and not NUL

This commit is contained in:
Werner Almesberger 2012-05-23 16:44:44 -03:00
parent 9445f2c85b
commit b9066c6331
2 changed files with 19 additions and 0 deletions

View File

@ -38,3 +38,21 @@ const char *unique(const char *s)
}
return u;
}
const char *unique_n(const char *s, int n)
{
char *tmp, *u;
if (!tree)
tree = g_tree_new(comp);
tmp = stralloc_n(s, n);
u = g_tree_lookup(tree, tmp);
if (u) {
free(tmp);
return u;
} else {
g_tree_insert(tree, tmp, tmp);
return tmp;
}
}

View File

@ -50,5 +50,6 @@ static inline char *stralloc_n(const char *s, int n)
const char *unique(const char *s);
const char *unique_n(const char *s, int n);
#endif /* !UTIL_H */