为什么 setupterm 会终止程序?

Ale*_*x F 3 c linux terminfo

这是《Linux 编程入门》一书中的示例程序:

#include <stdio.h>
#include <term.h>
#include <curses.h>
#include <stdlib.h>

int main()
{
    setupterm("未列出", fileno(stdout), (int *)0);
    printf("完成。\n");
    退出(0);
}

运行它,我得到这个结果:

./坏术语
“未列出”:未知的终端类型。

根据setupterm函数定义,它必须返回0:“terminfo数据库中没有匹配的条目”。相反,程序会终止。为什么?

Gre*_*ill 5

看来是你要求它这样做的。从man setupterm我的机器上:

  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.
Run Code Online (Sandbox Code Playgroud)

据推测,如果您想自己处理任何错误返回,则必须为(第三个)参数提供非 NULL 指针值errret