Why does setupterm terminate the program?



This is sample program from “Beginning Linux Programming” book:

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

int main()
    setupterm("unlisted", fileno(stdout), (int *)0);

Running it, I have this result:

'unlisted': unknown terminal type.

According to setupterm function definition, it must return 0: “No matching entry in terminfo database”. Instead of this, program terminates. Why?


It looks like you asked it to do so. From man setupterm on my machine:

  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.

Presumably, if you want to handle any error return yourself, you must supply a non-NULL pointer value for the errret (third) parameter.

Answered By – Greg Hewgill

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More