@@ -87,9 +87,9 @@ static int _FAT_directory_lfnLength (const char* name) {
8787 int ucsLength ;
8888 const char * tempName = name ;
8989
90- nameLength = strnlen (name , MAX_FILENAME_LENGTH );
90+ nameLength = strnlen (name , NAME_MAX );
9191 // Make sure the name is short enough to be valid
92- if ( nameLength >= MAX_FILENAME_LENGTH ) {
92+ if ( nameLength >= NAME_MAX ) {
9393 return -1 ;
9494 }
9595 // Make sure it doesn't contain any invalid characters
@@ -364,7 +364,7 @@ bool _FAT_directory_getNextEntry (PARTITION* partition, DIR_ENTRY* entry) {
364364 }
365365
366366 if (lfnExists ) {
367- if (_FAT_directory_ucs2tombs (entry -> filename , lfn , MAX_FILENAME_LENGTH ) == (size_t )-1 ) {
367+ if (_FAT_directory_ucs2tombs (entry -> filename , lfn , NAME_MAX ) == (size_t )-1 ) {
368368 // Failed to convert the file name to UTF-8. Maybe the wrong locale is set?
369369 return false;
370370 }
@@ -405,7 +405,7 @@ bool _FAT_directory_getRootEntry (PARTITION* partition, DIR_ENTRY* entry) {
405405
406406 entry -> dataEnd = entry -> dataStart ;
407407
408- memset (entry -> filename , '\0' , MAX_FILENAME_LENGTH );
408+ memset (entry -> filename , '\0' , NAME_MAX );
409409 entry -> filename [0 ] = '.' ;
410410
411411 memset (entry -> entryData , 0 , DIR_ENTRY_DATA_SIZE );
@@ -474,7 +474,7 @@ bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry) {
474474 int lfnPos ;
475475 uint8_t entryData [DIR_ENTRY_DATA_SIZE ];
476476
477- memset (entry -> filename , '\0' , MAX_FILENAME_LENGTH );
477+ memset (entry -> filename , '\0' , NAME_MAX );
478478
479479 // Create an empty directory entry to overwrite the old ones with
480480 for ( entryStillValid = true, finished = false;
@@ -516,7 +516,7 @@ bool _FAT_directory_entryFromPosition (PARTITION* partition, DIR_ENTRY* entry) {
516516 }
517517 } else {
518518 // Encode the long file name into a multibyte string
519- if (_FAT_directory_ucs2tombs (entry -> filename , lfn , MAX_FILENAME_LENGTH ) == (size_t )-1 ) {
519+ if (_FAT_directory_ucs2tombs (entry -> filename , lfn , NAME_MAX ) == (size_t )-1 ) {
520520 return false;
521521 }
522522 }
@@ -571,7 +571,7 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
571571 dirnameLength = strlen (pathPosition );
572572 }
573573
574- if (dirnameLength > MAX_FILENAME_LENGTH ) {
574+ if (dirnameLength > NAME_MAX ) {
575575 // The path is too long to bother with
576576 return false;
577577 }
@@ -589,7 +589,7 @@ bool _FAT_directory_entryFromPath (PARTITION* partition, DIR_ENTRY* entry, const
589589
590590 while (foundFile && !found && !notFound ) { // It hasn't already found the file
591591 // Check if the filename matches
592- if ((dirnameLength == strnlen (entry -> filename , MAX_FILENAME_LENGTH ))
592+ if ((dirnameLength == strnlen (entry -> filename , NAME_MAX ))
593593 && (_FAT_directory_mbsncasecmp (pathPosition , entry -> filename , dirnameLength ) == 0 )) {
594594 found = true;
595595 }
@@ -758,9 +758,9 @@ static bool _FAT_directory_entryExists (PARTITION* partition, const char* name,
758758 char alias [MAX_ALIAS_LENGTH ];
759759 size_t dirnameLength ;
760760
761- dirnameLength = strnlen (name , MAX_FILENAME_LENGTH );
761+ dirnameLength = strnlen (name , NAME_MAX );
762762
763- if (dirnameLength >= MAX_FILENAME_LENGTH ) {
763+ if (dirnameLength >= NAME_MAX ) {
764764 return false;
765765 }
766766
@@ -769,7 +769,7 @@ static bool _FAT_directory_entryExists (PARTITION* partition, const char* name,
769769
770770 while (foundFile ) { // It hasn't already found the file
771771 // Check if the filename matches
772- if ((dirnameLength == strnlen (tempEntry .filename , MAX_FILENAME_LENGTH ))
772+ if ((dirnameLength == strnlen (tempEntry .filename , NAME_MAX ))
773773 && (_FAT_directory_mbsncasecmp (name , tempEntry .filename , dirnameLength ) == 0 )) {
774774 return true;
775775 }
@@ -808,7 +808,7 @@ static int _FAT_directory_createAlias (char* alias, const char* lfn) {
808808
809809 // Primary portion of alias
810810 while (aliasPos < 8 && lfn [lfnPos ] != '.' && lfn [lfnPos ] != '\0' ) {
811- bytesUsed = mbrtowc (& lfnChar , lfn + lfnPos , MAX_FILENAME_LENGTH - lfnPos , & ps );
811+ bytesUsed = mbrtowc (& lfnChar , lfn + lfnPos , NAME_MAX - lfnPos , & ps );
812812 if (bytesUsed < 0 ) {
813813 return -1 ;
814814 }
@@ -855,7 +855,7 @@ static int _FAT_directory_createAlias (char* alias, const char* lfn) {
855855 aliasPos ++ ;
856856 memset (& ps , 0 , sizeof (ps ));
857857 for (aliasExtLen = 0 ; aliasExtLen < MAX_ALIAS_EXT_LENGTH && * lfnExt != '\0' ; aliasExtLen ++ ) {
858- bytesUsed = mbrtowc (& lfnChar , lfnExt , MAX_FILENAME_LENGTH - lfnPos , & ps );
858+ bytesUsed = mbrtowc (& lfnChar , lfnExt , NAME_MAX - lfnPos , & ps );
859859 if (bytesUsed < 0 ) {
860860 return -1 ;
861861 }
@@ -923,7 +923,7 @@ bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t d
923923#endif
924924
925925 // Make sure the filename is not 0 length
926- if (strnlen (entry -> filename , MAX_FILENAME_LENGTH ) < 1 ) {
926+ if (strnlen (entry -> filename , NAME_MAX ) < 1 ) {
927927 return false;
928928 }
929929
@@ -935,7 +935,7 @@ bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t d
935935
936936 // Remove junk in filename
937937 i = strlen (entry -> filename );
938- memset (entry -> filename + i , '\0' , MAX_FILENAME_LENGTH - i );
938+ memset (entry -> filename + i , '\0' , NAME_MAX - i );
939939
940940 // Make sure the entry doesn't already exist
941941 if (_FAT_directory_entryExists (partition , entry -> filename , dirCluster )) {
@@ -945,11 +945,11 @@ bool _FAT_directory_addEntry (PARTITION* partition, DIR_ENTRY* entry, uint32_t d
945945 // Clear out alias, so we can generate a new one
946946 memset (entry -> entryData , ' ' , 11 );
947947
948- if ( strncmp (entry -> filename , "." , MAX_FILENAME_LENGTH ) == 0 ) {
948+ if ( strncmp (entry -> filename , "." , NAME_MAX ) == 0 ) {
949949 // "." entry
950950 entry -> entryData [0 ] = '.' ;
951951 entrySize = 1 ;
952- } else if ( strncmp (entry -> filename , ".." , MAX_FILENAME_LENGTH ) == 0 ) {
952+ } else if ( strncmp (entry -> filename , ".." , NAME_MAX ) == 0 ) {
953953 // ".." entry
954954 entry -> entryData [0 ] = '.' ;
955955 entry -> entryData [1 ] = '.' ;
0 commit comments