gpt4 book ai didi

UNIX 'comm' 实用程序允许在 BSD 中不区分大小写,但在 Linux 中不允许(通过 -i 标志)。我如何在 Linux 中获取它?

转载 作者:行者123 更新时间:2023-12-04 21:50:25 25 4
gpt4 key购买 nike

我在 BSD 平台 (OSX) 上开发的应用程序中使用了出色的 UNIX“comm”命令行实用程序。当我部署到我的 Linux 生产服务器时,我遗憾地发现,Ubuntu Linux 的“comm”实用程序没有使用 -i 标志来指示行比较时不区分大小写。显然 POSIX 标准不需要 -i 选项。

所以……我进退两难了。我真的需要在 BSD 上运行良好的 -i 选项。到目前为止,我一直在尝试在 Linux 机器上编译 BSD comm.c 源代码,但我得到了:

http://svn.freebsd.org/viewvc/base/user/luigi/ipfw3-head/usr.bin/comm/comm.c?view=markup&pathrev=200559

me@host:~$ gcc comm.c 
comm.c: In function ‘getline’:
comm.c:195: warning: assignment makes pointer from integer without a cast
comm.c: In function ‘wcsicoll’:
comm.c:264: warning: assignment makes pointer from integer without a cast
comm.c:270: warning: assignment makes pointer from integer without a cast
/tmp/ccrvPbfz.o: In function `getline':
comm.c:(.text+0x421): undefined reference to `reallocf'
/tmp/ccrvPbfz.o: In function `wcsicoll':
comm.c:(.text+0x691): undefined reference to `reallocf'
comm.c:(.text+0x6ef): undefined reference to `reallocf'
collect2: ld returned 1 exit status

对于如何在 Linux 上获得支持“comm -i”的 comm 版本,有人有任何建议吗?

谢谢!

最佳答案

您可以在 comm.c 中添加以下内容:

void *reallocf(void *ptr, size_t size)
{
void *ret = realloc(ptr, size);
if (ret == NULL) {
free(ptr);
}
return ret;
}

你应该可以编译它了。确保 comm.c#include <stdlib.h>在其中(它可能已经这样做了)。

编译失败的原因是 BSD comm.c使用 reallocf()这不是标准的 C 函数。但是很容易写。

关于UNIX 'comm' 实用程序允许在 BSD 中不区分大小写,但在 Linux 中不允许(通过 -i 标志)。我如何在 Linux 中获取它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2153371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com