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
This commit is contained in:
Jeffrey Altman
2011-07-21 11:40:04 -04:00
parent b8ce309acb
commit b7df4f8bb3

View File

@@ -64,6 +64,7 @@ filespec_from_dir_path(const char * path, char * buffer, size_t cch_buffer)
{ {
char *comp, *t; char *comp, *t;
size_t pos; size_t pos;
int found_sep = 0;
if (strcpy_s(buffer, cch_buffer, path) != 0) if (strcpy_s(buffer, cch_buffer, path) != 0)
return NULL; return NULL;
@@ -71,12 +72,17 @@ filespec_from_dir_path(const char * path, char * buffer, size_t cch_buffer)
comp = strrchr(buffer, '\\'); comp = strrchr(buffer, '\\');
if (comp == NULL) if (comp == NULL)
comp = buffer; comp = buffer;
else
found_sep = 1;
t = strrchr(comp, '/'); t = strrchr(comp, '/');
if (t != NULL) if (t != NULL) {
comp = t; comp = t;
found_sep = 1;
}
comp++; if (found_sep)
comp++;
pos = strcspn(comp, "*?"); pos = strcspn(comp, "*?");
if (comp[pos] != '\0') if (comp[pos] != '\0')