@@ -86,7 +86,7 @@ int _FAT_link_r (struct _reent *r, const char *existing, const char *newLink) {
8686 return -1 ;
8787}
8888
89- int _FAT_unlink_r (struct _reent * r , const char * path ) {
89+ static int _FAT_unlinkCommon (struct _reent * r , const char * path , bool isRmDir ) {
9090 PARTITION * partition = NULL ;
9191 DIR_ENTRY dirEntry ;
9292 DIR_ENTRY dirContents ;
@@ -130,6 +130,12 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
130130
131131 // If this is a directory, make sure it is empty
132132 if (_FAT_directory_isDirectory (& dirEntry )) {
133+ if (!isRmDir ) {
134+ _FAT_unlock (& partition -> lock );
135+ r -> _errno = EISDIR ;
136+ return -1 ;
137+ }
138+
133139 nextEntry = _FAT_directory_getFirstEntry (partition , & dirContents , cluster );
134140
135141 while (nextEntry ) {
@@ -141,6 +147,10 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
141147 }
142148 nextEntry = _FAT_directory_getNextEntry (partition , & dirContents );
143149 }
150+ } else if (isRmDir ) {
151+ _FAT_unlock (& partition -> lock );
152+ r -> _errno = ENOTDIR ;
153+ return -1 ;
144154 }
145155
146156 if (_FAT_fat_isValidCluster (partition , cluster )) {
@@ -171,6 +181,10 @@ int _FAT_unlink_r (struct _reent *r, const char *path) {
171181 }
172182}
173183
184+ int _FAT_unlink_r (struct _reent * r , const char * path ) {
185+ return _FAT_unlinkCommon (r , path , false);
186+ }
187+
174188int _FAT_chdir_r (struct _reent * r , const char * path ) {
175189 PARTITION * partition = NULL ;
176190
@@ -451,6 +465,10 @@ int _FAT_mkdir_r (struct _reent *r, const char *path, int mode) {
451465 return 0 ;
452466}
453467
468+ int _FAT_rmdir_r (struct _reent * r , const char * path ) {
469+ return _FAT_unlinkCommon (r , path , true);
470+ }
471+
454472int _FAT_statvfs_r (struct _reent * r , const char * path , struct statvfs * buf )
455473{
456474 PARTITION * partition = NULL ;
0 commit comments