Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions source/fatdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
bool fileExists;
DIR_ENTRY dirEntry;
const char* pathEnd;
const char* trailingSlash;
uint32_t parentCluster, dirCluster;
uint8_t newEntryData[DIR_ENTRY_DATA_SIZE];

Expand Down Expand Up @@ -376,8 +377,12 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
}

// Get the directory it has to go in
pathEnd = strrchr (path, DIR_SEPARATOR);
if (pathEnd == NULL) {
pathEnd = path + strlen (path) - 1;
trailingSlash = *pathEnd == DIR_SEPARATOR ? pathEnd : NULL;
if (trailingSlash) pathEnd--;
while (pathEnd > path && *pathEnd != DIR_SEPARATOR)
--pathEnd;
if (pathEnd == path) {
// No path was specified
parentCluster = partition->cwdCluster;
pathEnd = path;
Expand All @@ -396,6 +401,10 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
}
// Create the entry data
strncpy (dirEntry.filename, pathEnd, NAME_MAX - 1);
if (trailingSlash) {
// Remove the trailing slash
dirEntry.filename[trailingSlash - pathEnd] = '\0';
}
memset (dirEntry.entryData, 0, DIR_ENTRY_DATA_SIZE);

// Set the creation time and date
Expand Down