Index: src/backend/utils/adt/like.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/like.c,v
retrieving revision 1.62
diff -u -r1.62 like.c
--- src/backend/utils/adt/like.c	15 Oct 2005 02:49:28 -0000	1.62
+++ src/backend/utils/adt/like.c	26 Nov 2005 19:46:24 -0000
@@ -72,38 +72,32 @@
  */
 #define CHARMAX 0x80
 
-static int
-iwchareq(char *p1, char *p2)
+static pg_wchar
+mbtolower(char *t)
 {
-	pg_wchar	c1[2],
-				c2[2];
+	pg_wchar	c[2];
 	int			l;
 
-	/*
-	 * short cut. if *p1 and *p2 is lower than CHARMAX, then we could assume
-	 * they are ASCII
-	 */
-	if ((unsigned char) *p1 < CHARMAX && (unsigned char) *p2 < CHARMAX)
-		return (tolower((unsigned char) *p1) == tolower((unsigned char) *p2));
+	l = pg_mblen(t);
+	(void) pg_mb2wchar_with_len(t, c, l);
+	return tolower(c[0]);
+}
 
-	/*
-	 * if one of them is an ASCII while the other is not, then they must be
-	 * different characters
-	 */
-	else if ((unsigned char) *p1 < CHARMAX || (unsigned char) *p2 < CHARMAX)
-		return (0);
+static int
+iwchareq(char *p1, char *p2)
+{
+	pg_wchar	c1, c2;
 
 	/*
-	 * ok, p1 and p2 are both > CHARMAX, then they must be multibyte
-	 * characters
+	 * Lowercasing by looking at if the character is
+	 * ASCII (< CHARMAX) or not.
 	 */
-	l = pg_mblen(p1);
-	(void) pg_mb2wchar_with_len(p1, c1, l);
-	c1[0] = tolower(c1[0]);
-	l = pg_mblen(p2);
-	(void) pg_mb2wchar_with_len(p2, c2, l);
-	c2[0] = tolower(c2[0]);
-	return (c1[0] == c2[0]);
+	c1 = ((unsigned char) *p1 < CHARMAX)
+		 ? tolower((unsigned char) *p1) : mbtolower(p1);
+	c2 = ((unsigned char) *p2 < CHARMAX)
+		 ? tolower((unsigned char) *p2) : mbtolower(p2);
+
+	return (c1 == c2);
 }
 
 #define CHAREQ(p1, p2) wchareq(p1, p2)
Index: src/backend/utils/adt/oracle_compat.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v
retrieving revision 1.64
diff -u -r1.64 oracle_compat.c
--- src/backend/utils/adt/oracle_compat.c	4 Nov 2005 22:19:04 -0000	1.64
+++ src/backend/utils/adt/oracle_compat.c	26 Nov 2005 19:46:25 -0000
@@ -258,6 +258,22 @@
 #define wcstotext	win32_wcstotext
 #endif   /* WIN32 */
 
+static pg_wchar
+mb2wchar_with_len(char inp)
+{
+	char		t[1];
+	pg_wchar	c[2];
+	int			l;
+
+	t[0] = inp;
+	l = pg_mblen(t);
+	(void) pg_mb2wchar_with_len(t, c, l);
+	return c[0];
+}
+
+#define mbtolower(t)	tolower(mb2wchar_with_len(t))
+#define mbtoupper(t)	toupper(mb2wchar_with_len(t))
+
 
 /********************************************************************
  *
@@ -293,7 +309,7 @@
 		workspace = texttowcs(string);
 
 		for (i = 0; workspace[i] != 0; i++)
-			workspace[i] = towlower(workspace[i]);
+			workspace[i] = mbtolower(workspace[i]);
 
 		result = wcstotext(workspace, i);
 
@@ -359,7 +375,7 @@
 		workspace = texttowcs(string);
 
 		for (i = 0; workspace[i] != 0; i++)
-			workspace[i] = towupper(workspace[i]);
+			workspace[i] = mbtoupper(workspace[i]);
 
 		result = wcstotext(workspace, i);
 
