UNIX & GNU/Linux - System calls - Using tgetflag()

The tgetflag() function is a Linux system call function. It is designed to be used with the getenv() and tgetent() functions.
The tgetflag() function returns a boolean value: 1 on success or 0 on fail.

With the tgetflag() function, we have to put an only one string parameter. You have to use the two letters of the appropriate termcaps. You can find all of them in the Boolean Capabilities of the termcap manual.

Let's see an example of the tgetflag() function with to show if our terminal has a status line (hs):

/*                                                                         
** Made by BadproG.com                                                     
*/

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

int     main()
{
  const char *name;
  char  *bp;
  char  *term;
  int   flag;

  bp = malloc(sizeof(*bp));
  name = "TERM";
  if ((term = getenv(name)) == NULL)
    return (1);
  printf("My terminal is %s.\n", term);
  tgetent(bp, term);
  flag = tgetflag("hs");
  printf("flag hs = %d\n", flag);
  free(bp);
  return (0);
}

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.