File: ioctl_winsize.c

package info (click to toggle)
strace 6.1-0.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 64,424 kB
  • sloc: ansic: 160,349; sh: 9,223; makefile: 3,817; cpp: 944; awk: 353; perl: 267; exp: 62; sed: 9
file content (43 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download | duplicates (9)
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
38
39
40
41
42
43
/*
 * Check decoding of ioctl TIOC[GS]WINSZ commands.
 *
 * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io>
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include <stdio.h>
#include <sys/ioctl.h>

int
main(void)
{
	int rc;

	rc = ioctl(-1, TIOCGWINSZ, 0);
	printf("ioctl(-1, TIOCGWINSZ, NULL) = %s\n", sprintrc(rc));

	rc = ioctl(-1, TIOCSWINSZ, 0);
	printf("ioctl(-1, TIOCSWINSZ, NULL) = %s\n", sprintrc(rc));

	TAIL_ALLOC_OBJECT_CONST_PTR(struct winsize, ws);
	const void *const efault = ws + 1;
	fill_memory(ws, sizeof(*ws));

	rc = ioctl(-1, TIOCSWINSZ, efault);
	printf("ioctl(-1, TIOCSWINSZ, %p) = %s\n", efault, sprintrc(rc));

	rc = ioctl(-1, TIOCGWINSZ, ws);
	printf("ioctl(-1, TIOCGWINSZ, %p) = %s\n", ws, sprintrc(rc));

	rc = ioctl(-1, TIOCSWINSZ, ws);
	printf("ioctl(-1, TIOCSWINSZ, {ws_row=%u, ws_col=%u"
	       ", ws_xpixel=%u, ws_ypixel=%u}) = %s\n",
	       ws->ws_row, ws->ws_col, ws->ws_xpixel, ws->ws_ypixel,
	       sprintrc(rc));

	puts("+++ exited with 0 +++");
	return 0;
}