#endif
/*
- * Convert a string to lowercase.
+ * Convert a string to lowercase. Converts at most 'len' characters,
+ * 'len' may be larger than the length of 'str' if 'str' is NULL
+ * terminated.
*/
-static void downcase(char *str)
+static void downcase(char *str, size_t len)
{
- while (*str != '\0') {
+ while (*str != '\0' && len--) {
*str = tolower(*str);
str++;
}
ptr = s_name;
while (*ptr && *ptr != ' ')
ptr++;
+ if (dirent->lcase & CASE_LOWER_BASE)
+ downcase(s_name, (unsigned)(ptr - s_name));
if (dirent->ext[0] && dirent->ext[0] != ' ') {
- *ptr = '.';
- ptr++;
+ *ptr++ = '.';
memcpy(ptr, dirent->ext, 3);
+ if (dirent->lcase & CASE_LOWER_EXT)
+ downcase(ptr, 3);
ptr[3] = '\0';
while (*ptr && *ptr != ' ')
ptr++;
*s_name = '\0';
else if (*s_name == aRING)
*s_name = DELETED_FLAG;
- downcase(s_name);
}
static int flush_dirty_fat_buffer(fsdata *mydata);
*l_name = '\0';
else if (*l_name == aRING)
*l_name = DELETED_FLAG;
- downcase(l_name);
+ downcase(l_name, INT_MAX);
/* Return the real directory entry */
*retdent = realdent;
memcpy(l_filename, filename, name_len);
l_filename[name_len] = 0; /* terminate the string */
- downcase(l_filename);
+ downcase(l_filename, INT_MAX);
startsect = mydata->rootdir_sect;
retdent = find_directory_entry(mydata, startsect,
/* Boot sign comes last, 2 bytes */
} volume_info;
+/* see dir_entry::lcase: */
+#define CASE_LOWER_BASE 8 /* base (name) is lower case */
+#define CASE_LOWER_EXT 16 /* extension is lower case */
+
typedef struct dir_entry {
char name[8],ext[3]; /* Name and extension */
__u8 attr; /* Attribute bits */
- __u8 lcase; /* Case for base and extension */
+ __u8 lcase; /* Case for name and ext (CASE_LOWER_x) */
__u8 ctime_ms; /* Creation time, milliseconds */
__u16 ctime; /* Creation time */
__u16 cdate; /* Creation date */