88 | | return strcmp (str1, str2); |
| 91 | /* To compare two string with locale specific characters correctly, |
| 92 | we need to convert it to wide characters and compare resulting |
| 93 | strings. |
| 94 | Note: this is really working solution for remark above :) |
| 95 | */ |
| 96 | /* Allocating memory for first string */ |
| 97 | result=mbsrtowcs(0,&str1,0,0); |
| 98 | if (result > 0) { |
| 99 | result=(result+1)*sizeof(wchar_t); |
| 100 | s1=(wchar_t *)malloc(result*sizeof(wchar_t)); |
| 101 | if (s1) memset(s1,result,1); |
| 102 | else |
| 103 | /* No memory. Returning standard comparision result */ |
| 104 | return strcmp (str1, str2); |
| 105 | }; |
| 106 | /* Allocating memory for second string */ |
| 107 | result=mbsrtowcs(0,&str2,0,0); |
| 108 | if (result > 0) { |
| 109 | result=(result+1)*sizeof(wchar_t); |
| 110 | s2=(wchar_t *)malloc(result*sizeof(wchar_t)); |
| 111 | if (s2) memset(s2,result,1); |
| 112 | else { |
| 113 | /* No memory. Returning standard comparision result */ |
| 114 | free(s1); |
| 115 | return strcmp (str1, str2); |
| 116 | }; |
| 117 | }; |
| 118 | /* Converting strings */ |
| 119 | mbsrtowcs(s1,&str1,strlen(str1),0); |
| 120 | mbsrtowcs(s2,&str2,strlen(str2),0); |
| 121 | /* Comparing and returning result */ |
| 122 | result=wcscmp(s1, s2); |
| 123 | free(s1); |
| 124 | free(s2); |
| 125 | return result; |