C 为什么setupterm会终止程序?
这是《开始Linux编程》一书中的示例程序: #包括 #包括 #包括 #包括 int main() { setupterm(“未上市”,文件号(标准输出),(int*)0; printf(“完成。\n”); 出口(0); } 运行它,我得到以下结果: ./badterm 'unlisted': unknown terminal type. /坏话 “未列出”:未知的终端类型。C 为什么setupterm会终止程序?,c,linux,terminfo,C,Linux,Terminfo,这是《开始Linux编程》一书中的示例程序: #包括 #包括 #包括 #包括 int main() { setupterm(“未上市”,文件号(标准输出),(int*)0; printf(“完成。\n”); 出口(0); } 运行它,我得到以下结果: ./badterm 'unlisted': unknown terminal type. /坏话 “未列出”:未知的终端类型。 根据setupterm函数定义,它必须返回0:“terminfo数据库中没有匹配项”。相反,程序终止。为什么?看起来是
根据setupterm函数定义,它必须返回0:“terminfo数据库中没有匹配项”。相反,程序终止。为什么?看起来是你让它这么做的。从我的机器上的
man setupterm
:
假设,如果您希望自己处理任何错误返回,则必须为errret
(第三个)参数提供非空指针值
./badterm
'unlisted': unknown terminal type.
If errret is null, setupterm prints an error message upon finding an
error and exits. Thus, the simplest call is:
setupterm((char *)0, 1, (int *)0);
which uses all the defaults and sends the output to stdout.