Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does setupterm terminate the program?

Tags:

c

linux

terminfo

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);
    printf("Done.\n");
    exit(0);
}

Running it, I have this result:

./badterm 
'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?

like image 381
Alex F Avatar asked Dec 15 '25 09:12

Alex F


1 Answers

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.

like image 113
Greg Hewgill Avatar answered Dec 16 '25 23:12

Greg Hewgill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!