From 3f9da410144fd45ee6250dda28cae49300077e29 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Wed, 17 Jul 2013 15:53:33 +0200 Subject: Fixes for some recent win32 regressions --- common/path.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'common') diff --git a/common/path.c b/common/path.c index 89d9a67..818befc 100644 --- a/common/path.c +++ b/common/path.c @@ -228,6 +228,7 @@ p11_path_build (const char *path, size_t len; size_t at; size_t num; + size_t until; va_list va; return_val_if_fail (path != NULL, NULL); @@ -247,14 +248,28 @@ p11_path_build (const char *path, path = first; va_start (va, path); while (path != NULL) { - if (at != 0 && built[at - 1] != delim && path[0] != delim) - built[at++] = delim; num = strlen (path); + + /* Trim end of the path */ + until = (at > 0) ? 0 : 1; + while (num > until && is_path_component_or_null (path[num - 1])) + num--; + + if (at != 0) { + if (num == 0) + continue; + built[at++] = delim; + } + assert (at + num < len); memcpy (built + at, path, num); - at += num; + path = va_arg (va, const char *); + + /* Trim beginning of path */ + while (path && path[0] && is_path_component_or_null (path[0])) + path++; } va_end (va); -- cgit v1.1