Ticket #4: mc-4.6.0-sort-fix.patch

File mc-4.6.0-sort-fix.patch, 1.5 KB (added by slavazanko, 15 years ago)
  • mc-4.6.0/src/dir.c

    old new  
    8383static int string_sortcomp (char *str1, char *str2) 
    8484{ 
    8585    static strcoll_status use_strcoll = STRCOLL_TEST; 
     86    wchar_t *s1=0; 
     87    wchar_t *s2=0; 
     88    int result; 
    8689 
    8790    if (case_sensitive) { 
    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; 
    89126    } 
    90127 
    91128    /* Initialize use_strcoll once.  */