From aa9b77a56c302461e373cf447672aa93adff3130 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Jun 1998 13:39:54 +0000 Subject: [PATCH] replace calls to strcmp() with a u_strcmp() function that uses only 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 | 4 ++-- util.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/flist.c b/flist.c index 7a0db274..75920690 100644 --- 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 11e4a9d9..b80d5161 100644 --- 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; +} -- 2.34.1