2

这是“Beginning Linux Programming”一书中的示例程序:

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

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

运行它,我有这个结果:

./badterm
“未列出”:未知终端类型。

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

4

1 回答 1

3

看起来你要求它这样做。从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.

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

于 2010-06-07T11:53:15.613 回答