00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef HAVE_CONFIG_H
00021 # include <config.h>
00022 #endif
00023
00024
00025 #include "strcase.h"
00026
00027 #include <ctype.h>
00028 #include <limits.h>
00029
00030 #if HAVE_MBRTOWC
00031 # include "mbuiter.h"
00032 #endif
00033
00034 #define TOLOWER(Ch) (isupper (Ch) ? tolower (Ch) : (Ch))
00035
00036
00037
00038
00039
00040
00041 int
00042 strcasecmp (const char *s1, const char *s2)
00043 {
00044 if (s1 == s2)
00045 return 0;
00046
00047
00048
00049
00050 #if HAVE_MBRTOWC
00051 if (MB_CUR_MAX > 1)
00052 {
00053 mbui_iterator_t iter1;
00054 mbui_iterator_t iter2;
00055
00056 mbui_init (iter1, s1);
00057 mbui_init (iter2, s2);
00058
00059 while (mbui_avail (iter1) && mbui_avail (iter2))
00060 {
00061 int cmp = mb_casecmp (mbui_cur (iter1), mbui_cur (iter2));
00062
00063 if (cmp != 0)
00064 return cmp;
00065
00066 mbui_advance (iter1);
00067 mbui_advance (iter2);
00068 }
00069 if (mbui_avail (iter1))
00070
00071 return 1;
00072 if (mbui_avail (iter2))
00073
00074 return -1;
00075 return 0;
00076 }
00077 else
00078 #endif
00079 {
00080 const unsigned char *p1 = (const unsigned char *) s1;
00081 const unsigned char *p2 = (const unsigned char *) s2;
00082 unsigned char c1, c2;
00083
00084 do
00085 {
00086 c1 = TOLOWER (*p1);
00087 c2 = TOLOWER (*p2);
00088
00089 if (c1 == '\0')
00090 break;
00091
00092 ++p1;
00093 ++p2;
00094 }
00095 while (c1 == c2);
00096
00097 if (UCHAR_MAX <= INT_MAX)
00098 return c1 - c2;
00099 else
00100
00101
00102
00103 return (c1 > c2 ? 1 : c1 < c2 ? -1 : 0);
00104 }
00105 }