unsigned comparisons. Transferring files between two machines that
treated strcmp() differently led to the files being given the wrong
name at the destination if the filenames had characters > 128 (such as
Kanji characters) and the source and destination machines treated
strcmp() differently (ie. one treated strings as signed and the other
as unsigned).
We now treat all string comparisons for file list sorting as unsigned.
if (!(*f1)->basename) return -1;
if (!(*f2)->basename) return 1;
if ((*f1)->dirname == (*f2)->dirname)
- return strcmp((*f1)->basename, (*f2)->basename);
- return strcmp(f_name(*f1),f_name(*f2));
+ return u_strcmp((*f1)->basename, (*f2)->basename);
+ return u_strcmp(f_name(*f1),f_name(*f2));
}
return 0;
}
+
+/* we need to supply our own strcmp function for file list comparisons
+ to ensure that signed/unsigned usage is consistent between machines. */
+int u_strcmp(const char *cs1, const char *cs2)
+{
+ const uchar *s1 = (uchar *)cs1;
+ const uchar *s2 = (uchar *)cs2;
+
+ while (*s1 && *s2 && (*s1 == *s2)) {
+ s1++; s2++;
+ }
+
+ return (int)*s1 - (int)*s2;
+}