Incorrect collate when linking with static
Mitja Špes
mitja at lxnav.com
Tue Oct 19 09:11:52 EDT 2010
Hi all,
I'm trying to use locales for localized sorting but I stumbled across a
problem when compiling with '-static' flag.
If I use the static flag the sorting doesn't work correctly but it does so
if I compile with dynamic linking.
Testapp (look bellow) when compiled "arm-none-linux-gnueabi-gcc testapp.c -o
testapp" gives this output:
Locale set to sl_SI.utf8; Sorted: B C Ä (\xc4\x8c) D S Ĺ (\xc5\xa0)
This is the correct output.
Compiled with "arm-none-linux-gnueabi-gcc -static testapp.c -o testapp"
gives this output:
Locale set to sl_SI.utf8; Sorted: B C D S Ä (\xc4\x8c) Ĺ (\xc5\xa0)
Which is incorrect.
What am I doing wrong and how can I fix it so it will work with -static
compile?
Thank you for your help!
Mitja
------ testapp.c ------
#include <stdio.h>
#include <locale.h>
static int compare_ascii(const void *x, const void *y)
{
return strcoll(*(char **)x, *(char **)y);
}
int main(int argc, char **argv)
{
char *lines[]={ "S", "\xc4\x8c", "C", "B", "D", "\xc5\xa0" };
int i, nlines = 6;
char *p=setlocale(LC_COLLATE|LC_CTYPE, "sl_SI.utf8");
if(!p) {
printf("ERROR: Locale not set\r\n");
} else {
printf("Locale set to %s\r\n",p);
}
qsort(lines, nlines, sizeof(char *), compare_ascii);
printf("Sorted:\r\n");
for (i = 0; i < nlines; i++)
puts(lines[i]);
return 0;
}
---- end testapp.c ----
More information about the linux-arm
mailing list