summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/common/dir.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/firmware/common/dir.c b/firmware/common/dir.c
index f7f6171..e1f4c06 100644
--- a/firmware/common/dir.c
+++ b/firmware/common/dir.c
@@ -29,7 +29,9 @@ static bool busy=false;
DIR* opendir(char* name)
{
+ char namecopy[256];
char* part;
+ char* end;
struct fat_direntry entry;
struct fat_dir* dir = &(thedir.fatdir);
@@ -48,9 +50,11 @@ DIR* opendir(char* name)
return NULL;
}
- /* fixme: strtok() is not thread safe, and fat_getnext() calls yield() */
- for ( part = strtok(name, "/"); part;
- part = strtok(NULL, "/")) {
+ strncpy(namecopy,name,sizeof(namecopy));
+ namecopy[sizeof(namecopy)-1] = 0;
+
+ for ( part = strtok_r(namecopy, "/", &end); part;
+ part = strtok_r(NULL, "/", &end)) {
int partlen = strlen(part);
/* scan dir for name */
while (1) {