wcscoll函数被标记为中毒,我该怎么办?

时间:2013-01-15 07:55:20

标签: c macos darwin widechar

在Mac Os X 10.6.8上我无法使用标准库中的wchar_t函数编译代码,直到我解决了这个问题。

wcscoll函数以及其他一些函数:

  

inttypes.h :#pragma GCC毒药wcstoimax wcstoumax    stdlib.h :#pragma GCC毒药mbstowcs mbtowc wcstombs wctomb    wchar.h :#pragma GCC poison fgetws fputwc fputws fwprintf fwscanf mbrtowc mbsnrtowcs> mbsrtowcs putwc putwchar swprintf swscanf vfwprintf vfwscanf vswprintf vswscanf vwprintf> vwscanf wcrtomb wcscat wcschr wcscmp wcscoll wcscpy wcscspn wcsftime wcsftime wcslcat> wcslcpy wcslen wcsncat wcsncmp wcsncpy wcsnrtombs wcspbrk wcsrchr wcsrtombs wcsspn wcsstr> wcstod wcstof wcstok wcstol wcstold wcstoll wcstoul wcstoull wcswidth wcsxfrm wcwidth> wmemchr wmemcmp wmemcpy wmemove wmemset wprintf wscanf

#include  <stdio.h>
#include <wchar.h>
#include  <string.h>
#include  <locale.h>
#include  <stdlib.h>
extern  int  errno; 
int main(void)
{
wchar_t  pwcs1[3]={L"ØL"}, pwcs2[3]={L"Ål"};
size_t   n;
(void)setlocale(LC_ALL,  "");

 /*    set it to zero for checking errors on wcscoll    */
 errno  =  0;
/*
 **    Let pwcs1 and pwcs2 be two wide character strings to
 **    compare.
 */
 /* n  =  wcscmp(pwcs1, pwcs2); */
 n  =  wcscoll(pwcs1, pwcs2); 
     /*
     **    If errno is set then it indicates some
     **    collation error.
     */
if (n < 0 ) {
    printf("%s\n","Øl mindre en Ål" );
} else if (n == 0) {
    printf("%s\n","Øl lik Ål" );
} else {
    printf("%s\n","Øl større en Ål" );
}

 if(errno  !=  0){
     /*  error has occurred... handle error ...*/
 }
}

我该如何解决这个问题? 我有点不愿意弄乱标准库。但我想我也许可以编译GNU C库,如果Apple没有修复它?或者在库中有任何其他合适的替代方案来处理宽字符(Utf-8)。

我正在移植古老的东西,所以我真的需要使用ncurses,并且为了使用ncurses,我需要宽字符! :)

编辑:标准的includepath应该是,因为我已经理解为/ usr / include。我已经浏览了SDK的include目录,并且通过头文件的grep显示了相同的毒pragma,就像来自http://opensource.apple.com/tarballs/Libc/的最新tarball一样

修改++

Hindsightly,那些pragma是有原因的,我正在寻找替代品,所以现在,我正在尝试构建glibc,刚下载,我已经检查了标题,这些标题没有任何“GCC毒药”pragmas

稍微读了一下,在glibc的配置文件中,我想这不是一个简单的选择。我想我将不得不剖析一些与utf-8兼容的东西,并在mac osX上使用ncurses来弄清楚如何。

可能我只是忽略了一个简单的解决方案。但ncurses重新回到了7位ascii,这就是我的问题。我的目标是使用ncurses渲染utf-8语言特定字符。我需要能够排序,因为格式是“propritary”与索引,分叉系统调用排序记录是没有选择。我还需要能够知道在字符串中使用ncurses对字符进行字段编辑,插入和删除的字符串中有多少个代码点。

谢谢!

1 个答案:

答案 0 :(得分:0)

到目前为止,似乎ICU库看起来很有希望:我想我会继续寻求ICU库的解决方案,据我所知,这是Mac OS X附带的。http://icu-project.org/apiref/icu4c/