File: pty_size.c

package info (click to toggle)
haskell-posix-pty 0.2.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 104 kB
  • sloc: haskell: 242; ansic: 98; makefile: 6
file content (37 lines) | stat: -rw-r--r-- 584 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <sys/ioctl.h>

#include <string.h>

#include <HsFFI.h>

#include "pty_size.h"

int
set_pty_size(int fd, HsInt x, HsInt y)
{
    struct winsize ws;

    /* Set the terminal size and settings. */
    memset(&ws, 0, sizeof ws);
    ws.ws_col = x;
    ws.ws_row = y;

    return ioctl(fd, TIOCSWINSZ, &ws);
}

int
get_pty_size(int fd, HsInt *x, HsInt *y)
{
    int result;
    struct winsize ws;

    /* Set the terminal size and settings. */
    memset(&ws, 0, sizeof ws);
    result = ioctl(fd, TIOCGWINSZ, &ws);

    *x = ws.ws_col;
    *y = ws.ws_row;

    return result;
}