File: term.c

package info (click to toggle)
bidiv 1.4-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 76 kB
  • ctags: 19
  • sloc: ansic: 206; makefile: 67
file content (22 lines) | stat: -rw-r--r-- 417 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <sys/ioctl.h>
#include <stdlib.h>
#include <limits.h>
#include "term.h"

int term_size_get(void)
{
    struct winsize win;
    int cols;
    char *col_str;
    int err;

    err = ioctl(1, TIOCGWINSZ, (char *)&win);
    if (err != -1 && win.ws_col > 0)
	return win.ws_col;
 
    col_str = getenv("COLUMNS");
    if (!col_str || (cols = atoi(col_str)) <= 0 || cols == INT_MAX)
	cols = 80;

    return cols;
}