From b7df4f8bb37c44f214d56805478984a5fb496137 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Thu, 21 Jul 2011 11:40:04 -0400 Subject: [PATCH] dirent: fix filespec_from_dir_path If the path does not begin with a separator, do not advance skip the first character in the component referred to by 'comp'. Change-Id: Ide184ba2065bd8b2075be27b8e1f4cae11026fdd --- lib/roken/dirent.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/roken/dirent.c b/lib/roken/dirent.c index c76724c72..df4c270a6 100644 --- a/lib/roken/dirent.c +++ b/lib/roken/dirent.c @@ -64,6 +64,7 @@ filespec_from_dir_path(const char * path, char * buffer, size_t cch_buffer) { char *comp, *t; size_t pos; + int found_sep = 0; if (strcpy_s(buffer, cch_buffer, path) != 0) return NULL; @@ -71,12 +72,17 @@ filespec_from_dir_path(const char * path, char * buffer, size_t cch_buffer) comp = strrchr(buffer, '\\'); if (comp == NULL) comp = buffer; + else + found_sep = 1; t = strrchr(comp, '/'); - if (t != NULL) + if (t != NULL) { comp = t; + found_sep = 1; + } - comp++; + if (found_sep) + comp++; pos = strcspn(comp, "*?"); if (comp[pos] != '\0')