replace calls to strcmp() with a u_strcmp() function that uses only
authorAndrew Tridgell <tridge@samba.org>
Mon, 1 Jun 1998 13:39:54 +0000 (13:39 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 1 Jun 1998 13:39:54 +0000 (13:39 +0000)
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.

flist.c
util.c

diff --git a/flist.c b/flist.c
index 7a0db2744c1e292762ce2145edbb3e2c6b16f3a6..759206909f0d8b8475d6a23f018d42b8dbba48a0 100644 (file)
--- a/flist.c
+++ b/flist.c
@@ -757,8 +757,8 @@ int file_compare(struct file_struct **f1,struct file_struct **f2)
        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));
 }
 
 
diff --git a/util.c b/util.c
index 11e4a9d9b7c1012c79fd23880839f9c240e06046..b80d516112cc7dddbd72f5e059b255eb80fd49d9 100644 (file)
--- a/util.c
+++ b/util.c
@@ -653,3 +653,17 @@ int pop_dir(char *dir)
 
        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;
+}