Archived
1
0
Fork 0

path.c: dirname_s: allow 'path' to point to the static buffer.

feeding the function a pointer to sb.buf results in path also being cleared
by the call to strbuf_reduce and the information is lost.
This commit is contained in:
Henrik Hautakoski 2011-02-16 16:53:26 +02:00
parent 3c2436867e
commit a1a85267f0
2 changed files with 9 additions and 3 deletions

View file

@ -85,9 +85,11 @@ int path_isparent(const char *path, const char *parent) {
const char* dirname_s(const char *path, int slash) {
static strbuf_t sb = STRBUF_INIT;
strbuf_reduce(&sb, sb.len);
strbuf_append_str(&sb, path);
if (sb.buf != path) {
strbuf_setlen(&sb, 0);
strbuf_append_str(&sb, path);
}
strbuf_squeeze(&sb, '/');
if (sb.len > 1) {